我在这里关注 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
我该如何解决这些错误?我只是复制了他们给我的东西
索引.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);