【发布时间】:2011-11-27 17:42:23
【问题描述】:
我的代码基于http://gdatatips.blogspot.com/2008/11/2-legged-oauth-in-php.html。
这是我的代码,我想使用 Google Doc(文档列表)API:
$endpoint = 'https://www.google.com/accounts/OAuthGetRequestToken';
$consumer = new OAuthConsumer(GOOGLE_API_DOCLIST_CONSUMER_KEY, GOOGLE_API_DOCLIST_CONSUMER_SECRET, NULL);
$arrParams = array(
'scope' => 'https://docs.google.com/feeds/'
,'xoauth_requestor_id' => GOOGLE_API_DOCLIST_USER_EMAIL
);
$req = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $endpoint, $arrParams);
$req->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, null);
$curl = new Auth_Curl();
$content = $curl->request($req->to_url());
$docAPI = new GoogleAPI_DocumentList(new Auth_Curl(), $req->to_header());
var_dump($req->to_header());
echo '<br />-- Getting Collections list';
$url = 'https://docs.google.com/feeds/default/private/full/-/folder' . '?xoauth_requestor_id=' . GOOGLE_API_DOCLIST_USER_EMAIL;
$raw = $docAPI->getCollectionList($url);
var_dump($raw);
die();
我不断得到:
令牌无效 - AuthSub 令牌无效。
我做错了什么?
编辑: 这里有一些“提示”:
- 它们似乎混合了 API 端点和基本提要。我已经为端点放置了 OAuthGetRequestToken。它似乎产生了有效的响应。
- 我保留了它,但我不确定 xoauth_requestor_id 是必需的。
- 文档告诉我们使用空格分隔 Authorization 标头中的参数。图书馆使用逗号。
【问题讨论】: