コード例 #1
0
 protected function _finish($code, $originalRedirectUri)
 {
     // This endpoint requires "Basic" auth.
     $clientCredentials = $this->appInfo->getKey() . ":" . $this->appInfo->getSecret();
     $authHeaderValue = "Basic " . base64_encode($clientCredentials);
     $response = Dropbox_RequestUtil::doPostWithSpecificAuth($this->clientIdentifier, $authHeaderValue, $this->userLocale, $this->appInfo->getHost()->getApi(), "1/oauth2/token", array("grant_type" => "authorization_code", "code" => $code, "redirect_uri" => $originalRedirectUri));
     if ($response->statusCode !== 200) {
         throw Dropbox_RequestUtil::unexpectedStatus($response);
     }
     $parts = Dropbox_RequestUtil::parseResponseJson($response->body);
     if (!array_key_exists('token_type', $parts) or !is_string($parts['token_type'])) {
         throw new Dropbox_Exception_BadResponse("Missing \"token_type\" field.");
     }
     $tokenType = $parts['token_type'];
     if (!array_key_exists('access_token', $parts) or !is_string($parts['access_token'])) {
         throw new Dropbox_Exception_BadResponse("Missing \"access_token\" field.");
     }
     $accessToken = $parts['access_token'];
     if (!array_key_exists('uid', $parts) or !is_string($parts['uid'])) {
         throw new Dropbox_Exception_BadResponse("Missing \"uid\" string field.");
     }
     $userId = $parts['uid'];
     if ($tokenType !== "Bearer" && $tokenType !== "bearer") {
         throw new Dropbox_Exception_BadResponse("Unknown \"token_type\"; expecting \"Bearer\", got  " . Dropbox_Client::q($tokenType));
     }
     return array($accessToken, $userId);
 }
コード例 #2
0
 /**
  * Make a Dropbox API call to disable the given OAuth 1 access token.
  *
  * See <a href="https://www.dropbox.com/developers/core/docs#disable-token">/disable_access_token</a>.
  *
  * @param Dropbox_OAuth1AccessToken $oauth1AccessToken
  *
  * @throws Dropbox_Exception
  */
 public function disableOAuth1AccessToken($oauth1AccessToken)
 {
     Dropbox_OAuth1AccessToken::checkArg("oauth1AccessToken", $oauth1AccessToken);
     /** @handled static fix */
     $response = self::doPost($oauth1AccessToken, "1/disable_access_token");
     if ($response->statusCode !== 200) {
         throw Dropbox_RequestUtil::unexpectedStatus($response);
     }
 }
コード例 #3
0
ファイル: Client.php プロジェクト: onedaylabs/onedaylabs.com
 /**
  * Moves a file or folder to a new location.
  *
  * See <a href="https://www.dropbox.com/developers/core/docs#fileops-move">/fileops/move</a>.
  *
  * @param string $fromPath
  *                         The source Dropbox path (UTF-8).
  *
  * @param string $toPath
  *                       The destination Dropbox path (UTF-8).
  *
  * @return mixed
  *               The <a href="https://www.dropbox.com/developers/core/docs#metadata-details">metadata
  *               object</a> for the destination file or folder.
  *
  * @throws Dropbox_Exception
  */
 public function move($fromPath, $toPath)
 {
     Dropbox_Path::checkArgNonRoot("fromPath", $fromPath);
     Dropbox_Path::checkArgNonRoot("toPath", $toPath);
     $response = $this->doPost($this->apiHost, "1/fileops/move", array("root" => "auto", "from_path" => $fromPath, "to_path" => $toPath));
     if ($response->statusCode !== 200) {
         throw Dropbox_RequestUtil::unexpectedStatus($response);
     }
     return Dropbox_RequestUtil::parseResponseJson($response->body);
 }