我的代码基于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令牌。
我做错了什么?
编辑: 这里有一些“提示”:
答案 0 :(得分:1)
以下是更正后的代码:
$endpoint = 'https://docs.google.com/feeds/default/private/full/-/folder';
$consumer = new OAuthConsumer(GOOGLE_API_DOCLIST_CONSUMER_KEY, GOOGLE_API_DOCLIST_CONSUMER_SECRET, NULL);
$arrParams = array(
'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);
$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();