Dropbox无效访问令牌

时间:2013-05-05 20:38:56

标签: php dropbox-api

我在这里关注Dropbox API。 https://www.dropbox.com/developers/core/start/php

向下滚动页面,他们会将“我完整的代码”复制并粘贴到我的index.php中

访问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.

我去那里,点击“允许”按钮,我指示回来,没有其他事情发生。

我的错误控制台说,

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

我该如何解决这些错误?我刚刚复制了他们给我的东西

的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);

1 个答案:

答案 0 :(得分:1)

像这样编写的

STDIN是PHP的常量。默认情况下,此常量不存在,您必须自己定义它。

你可以这样做:

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