开发者

"your authorization header here", what's that?

I've implemented the Google API v3.0, but the documentation is always telling to put "your authorization header here".

What's the value we should pass as the authorization header ???

But they never mention where that value come from. Logically, I though it could be the $_SESSION['access_token'] value, but when I try this:

curl_setopt($ressource, CURLOPT_HTTPHEADER, array(
     "GData-Version: 3.0",
     "Authorization: Bearer " . http_build_query(json_decode($_SESSION['access_token']))
     ));

I'm obtaining the following error:

Unknown authorization header

Error 401

And after a lot of search, I've tried to prepend "OAuth " :

curl_setopt($ressource, CURLOPT_HTTPHEADER, array(
     "GData-Version: 3.0",
     "Authorization: OAuth " . http_build_query开发者_JS百科(json_decode($_SESSION['access_token']))
     ));

it will not work either, but at least the error seems more verbose :

Token invalid - Invalid AuthSub token.

Error 401

So, why are they talking about AuthSub, AFAIK ( and I don't feel like I know much ), I'm using OAuth 2.0, not AuthSub.

And searching again about that error leads me to a possible scope problem ( http://www.geoffmcqueen.com/2010/03/14/token-invalid-authsub-token-has-wrong-scope-oauth-google-problem/ ).

So I double check my scope. From the config.php apiConfig array:

'services' => array(
      /* ... */,
      'documentList' => array('scope' => 'https://docs.google.com/feeds/')
    )

Note that I've added the documentList scope myself.

My code:

        $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);

In case the question is not obvious for someone: What am I doing wrong here ?

Thanks for your input... I'm struggling with that for a while now ...


I believe http://code.google.com/apis/storage/docs/authentication.html is what you are looking for :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜