我已经实现了Google API v3.0,但是文档总是告诉我要把"您的授权头放在这里"。
我们应该传递什么值作为授权头?
但是他们从来没有提到这个值是从哪里来的。从逻辑上讲,我认为它可能是$_SESSION['access_token']值,但是当我尝试这样做时:
curl_setopt($ressource, CURLOPT_HTTPHEADER, array(
"GData-Version: 3.0",
"Authorization: Bearer " . http_build_query(json_decode($_SESSION['access_token']))
));
我得到以下错误:
未知授权头
错误401
经过多次搜索,我试着在前面加上"OAuth ":
curl_setopt($ressource, CURLOPT_HTTPHEADER, array(
"GData-Version: 3.0",
"Authorization: OAuth " . http_build_query(json_decode($_SESSION['access_token']))
));
也不会工作,但至少错误看起来更冗长:
Token invalid - AuthSub Token无效。
错误401
那么,为什么他们谈论AuthSub,我不觉得我知道很多,我使用的是OAuth 2.0,而不是AuthSub。
再次搜索这个错误导致我发现一个可能的作用域问题(http://www.geoffmcqueen.com/2010/03/14/token-invalid-authsub-token-has-wrong-scope-oauth-google-problem/)。
所以我再次检查我的范围。从config.php的apiConfig数组中:
'services' => array(
/* ... */,
'documentList' => array('scope' => 'https://docs.google.com/feeds/')
)
注意,我自己添加了documentList作用域。
我代码: $this->authenticate();
$arrAuth = json_decode($_SESSION['access_token']);
$authenticationHeader = "Bearer " . $arrAuth->access_token
$url = "https://docs.google.com" . "/feeds/default/private/full";
$atomContent = <<<ATOM
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns="http://www.w3.org/2005/Atom">
<category scheme="http://schemas.google.com/g/2005#kind"
term="http://schemas.google.com/docs/2007#folder"/>
<title>Example Collection</title>
</entry>
ATOM;
$ressource = curl_init();
curl_setopt($ressource, CURLOPT_URL, $url);
curl_setopt($ressource, CURLOPT_HTTPHEADER, array(
"GData-Version: 3.0",
"Authorization: {$authenticationHeader}"
));
curl_setopt($ressource, CURLOPT_TIMEOUT, 5);
curl_setopt($ressource, CURLOPT_POST, 1);
curl_setopt($ressource, CURLOPT_POSTFIELDS, $atomContent);
$httpResponse = curl_exec($ressource);
如果问题对某人来说不是很明显:我哪里做错了?
谢谢你的输入…
我相信http://code.google.com/apis/storage/docs/authentication.html就是你要找的:)