2

我一直遇到dropbox php api的问题,我只是想使用 getmeta 让它工作。但我不断收到以下错误??

我认为问题就在这里。

public function getToken($email, $password) {

        throw new Dropbox_Exception('This API method is deprecated as of the version 1 API');

    }

这是我的代码。

$consumerKey = 'oksergerg1x1r';
$consumerSecret = 'zexb0rg6h54tgzzb';

require($_SERVER['DOCUMENT_ROOT'] . '/wp/includes/Dropbox/autoload.php');

//session_start();
$oauth = new Dropbox_OAuth_Wordpress($consumerKey, $consumerSecret);

echo "<pre>";
print_r($oauth);
echo "</pre>";

// If the PHP OAuth extension is not available, you can try
// PEAR's HTTP_OAUTH instead.
// $oauth = new Dropbox_OAuth_PEAR($consumerKey, $consumerSecret);

$dropbox = new Dropbox_API($oauth);

$tokens = $dropbox->getToken('mrhandsome@example.org', 'secretpassword');

// You are recommended to save these tokens, note that you don't
// need to save the username and password, so just ask your user the 
// first time and then destroy them.

echo "Tokens:\n";
print_r($tokens);

所以我说 getToken 函数已经贬值了,那么我们应该使用什么来代替?

更新

好的,抱歉,谷歌搜索了一下,我发现新版本不再支持 getTokens,即使它们出于某种原因仍在示例中。

所以我现在很困惑。

我正在尝试设置一个应用程序,以便人们可以输入他们的保管箱电子邮件和密码。然后它将从他们的帐户中提取所有元数据。

使用新代码如何授予用户访问权限?如果他们没有电子邮件和密码,我如何获得正确的令牌???

抱歉,我真的很困惑,过去两天一直在努力解决这个问题。

4

1 回答 1

1

看看单元测试。它们应该被视为有关如何使用该库的更多最新示例。Dropbox 在最新版本的 API 中弃用了一些身份验证内容,这就是我们不得不在库中弃用它的原因。更新文档和示例在我的清单上,我真的很忙。

基本上,您需要执行以下操作:

在您的 Oauth 提供程序类上,调用:

$tokens = $oauth->getRequestToken();

然后将用户重定向到,$oauth->getAuthorizeUrl()以便他们可以通过 Dropbox 进行身份验证并批准您的访问。

最后,调用:

$tokens = $oauth->getAccessToken();
$oauth->setToken($tokens);

您可以存储$tokens在某处以供将来连接时使用。您将通过调用:

$oauth->setToken($tokens);
$dropbox = new Dropbox_API($oauth);

希望有帮助。您还可以做更多事情(例如为 Dropbox 提供回调 URL 以将用户重定向回)。只需检查源测试目录中的 APITests.php 文件和设置文件:https ://github.com/Dropbox-PHP/dropbox-php/tree/master/tests

于 2012-03-09T20:27:57.297 回答