简体   繁体   中英

Dropbox Invalid Access Token

Im following the Dropbox API here. https://www.dropbox.com/developers/core/start/php

Scrolling down the page they give you "the complete code" I copied and pasted that in my index.php

I get these instructions when visiting my index.php

1. Go to: https://www.dropbox.com/1/oauth/authorize?locale=en&oauth_token=9PURkb1SJoLJ4Z41&oauth_callback=http%3A%2F%2Flocalhost%2Fmax%2F
2. Click "Allow" (you might have to log in first)
3. Hit ENTER to continue.

I go there, click the "Allow" button and im directed back and nothing else happens.

My error console says,

PHP Notice:  Use of undefined constant STDIN - assumed 'STDIN' in /Applications/MAMP/htdocs/max/index.php on line 16
[05-May-2013 20:33:53 UTC] PHP Warning:  fgets() expects parameter 1 to be resource, string given in /Applications/MAMP/htdocs/max/index.php on line 16
[05-May-2013 20:33:54 UTC] PHP Fatal error:  Uncaught exception 'Dropbox\Exception_InvalidAccessToken' with message '
{"error": "Invalid or expired oauth_token"}' in /Applications/MAMP/htdocs/max/dropbox-sdk/Dropbox/RequestUtil.php:222
Stack trace:
#0 /Applications/MAMP/htdocs/max/dropbox-sdk/Dropbox/WebAuth.php(155): Dropbox\RequestUtil::unexpectedStatus(Object(Dropbox\HttpResponse))
#1 /Applications/MAMP/htdocs/max/index.php(19): Dropbox\WebAuth->finish(Object(Dropbox\RequestToken))
#2 {main}
  thrown in /Applications/MAMP/htdocs/max/dropbox-sdk/Dropbox/RequestUtil.php on line 222

How can i fix these errors? I just copied what they gave me

index.php

require_once "dropbox-sdk/Dropbox/autoload.php";

use \Dropbox as dbx;

$appInfo = dbx\AppInfo::loadFromJsonFile("config.json");

$dbxConfig = new dbx\Config($appInfo, "PHP-Example/1.0");

$webAuth = new dbx\WebAuth($dbxConfig);
list($requestToken, $authorizeUrl) = $webAuth->start('http://localhost/max/');

echo "1. Go to: " . $authorizeUrl . "<br>";
echo "2. Click \"Allow\" (you might have to log in first)<br>";
echo "3. Hit ENTER to continue.\n";
fgets(STDIN);


list($accessToken, $dropboxUserId) = $webAuth->finish($requestToken);
print "Access Token: " . $accessToken->serialize() . "\n";

$dbxClient = new dbx\Client($dbxConfig, $accessToken);
$accountInfo = $dbxClient->getAccountInfo();

print_r($accountInfo);

$f = fopen("working-draft.txt", "rb");
$result = $dbxClient->uploadFile("/working-draft.txt", dbx\WriteMode::add(), $f);
fclose($f);
print_r($result);

$folderMetadata = $dbxClient->getMetadataWithChildren($path);
print_r($folderMetadata);

$f = fopen("working-draft.txt", "w+b");
$fileMetadata = $dbxClient->getFile("/working-draft.txt", $f);
fclose($f);
print_r($fileMetadata);

STDIN written like that is a constant for PHP. And this constant doesn't exist by default, you must define it yourself.

You can do it like that :

define("STDIN", fopen('php://stdin','r'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM