Buzz API的未知授权标头错误 - 使用Zend OAuth

时间:2010-06-30 22:40:03

标签: php zend-framework buzz

以下是我在尝试创建新内容时不断得到的响应 活性:

{"error":{"errors":[{"message":"Unknown authorization
header","locationType":"header","location":"Authorization"}],"code":
401,"message":"Unknown authorization header"}}

这是我发送的请求(用于调试):

POST /buzz/v1/activities/@me/@self?alt=json HTTP/1.1
Host: www.googleapis.com
Connection: close
Accept-encoding: gzip, deflate
User-Agent: Zend_Http_Client
Content-Type: application/json
Authorization: OAuth
realm="",oauth_consumer_key="eawp.com",oauth_nonce="ce29b04ce6648fbb92efc8f08c1c0091",oauth_signature_method="HMAC-
SHA1",oauth_timestamp="1277934794",oauth_version="1.0",oauth_token="1%2FcBzo5ckGvCAm3wLWh1SDH3xQNoW--
yek1NVfUa1Qqns",oauth_signature="CUezSiMbvxyN1BTeb3uROlIx8gA%3D"
Content-Length: 86

{"data":{"object":{"type":"note","content":"Using OAuth with Twitter -
PHP Example"}}}

获取access_token的所有其他请求都运行正常,但是 现在我不太清楚为什么它不起作用。

**更新

为了更多地协助调试,以下是相关代码:

$config = array( 
  //'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER, 
  //'version' => '1.0', 
  //'signatureMethod' => 'HMAC-SHA1', 
  'callbackUrl' => $callback, 
  'siteUrl' => $url, 
  'consumerKey' => $consumerKey, 
  'consumerSecret' => $consumerPass 
); 
$statusMessage = $title; 
$token = unserialize($accessToken); 
$client = $token->getHttpClient($config); 
$client->setUri('https://www.googleapis.com/buzz/v1/activities/@me/ 
@self?alt=json'); 
$client->setMethod(Zend_Http_Client::POST); 
$client->setEncType(Zend_Http_Client::ENC_FORMDATA); 
$client->setHeaders('Content-Type: application/json'); 
                                $data = array( 
                                        'data'   => array( 
                                                'object'  => array( 
                                                        'type'     => 'note', 
                                                        'content'  => $statusMessage, 
                                                ), 
                                        ), 
                                ); 
                                $dataXml = "<entry xmlns='http://www.w3.org/2005/Atom' 
xmlns:activity='http://activitystrea.ms/spec/1.0'> 
                                                                                <activity:object> 
                                                                                    <activity:object-type>http://activitystrea.ms/schema/1.0/ 
note</activity:object-type> 
                                                                                    <content type='html'>$statusMessage<content> 
                                                                                  </activity:object> 
                                                                                </entry>"; 
//$client->setRawData($dataXml); 
$client->setRawData(Zend_Json::encode($data)); 
//$client->setParameterPost("content", $statusMessage); 
$response = $client->request(); 

**正如你所看到的,我用xml + atom和。进行了一些测试 json要求 - 两者都没有太大的运气。

你能看到任何明显的错误吗?另一个提醒我,我 我正在使用Zend_Oauth。

1 个答案:

答案 0 :(得分:1)

我有一些问题

使用选项:
'requestScheme'=&gt; Zend_Oauth :: REQUEST_SCHEME_QUERYSTRING
在你的$ config数组

这次改变后我的问题解决了

PS更多代码:


$OAuthConfiguration = array(
  'version' => '1.0',
  'requestScheme' => Zend_Oauth::REQUEST_SCHEME_QUERYSTRING,
  'signatureMethod' => 'HMAC-SHA1',
  'callbackUrl'=>'####',
  'requestTokenUrl' => 'https://www.google.com/accounts/OAuthGetRequestToken',
  'authorizeUrl' => 'https://www.google.com/buzz/api/auth/OAuthAuthorizeToken',
  'accessTokenUrl' => 'https://www.google.com/accounts/OAuthGetAccessToken',
  'consumerKey' => '####',
  'consumerSecret' => '####',
);
$OAuthConsumer = new Zend_Oauth_Consumer($OAuthConfiguration);

//authorizeOAuth
$params = array(
   'domain'=>'####',
   'scope'=>'https://www.googleapis.com/auth/buzz'
);
$token = $OAuthConsumer->getRequestToken($params);

$_SESSION['token']['buzz'] = serialize($token);

$OAuthConsumer->redirect($params);

//callbackOAuth
if (!empty($_GET) && isset($_SESSION['token']['buzz'])) {
    $token = $consumer->getAccessToken(
        $_GET,
        unserialize($_SESSION['token']['buzz'])
    );
    unset($_SESSION['token']);
    return serialize($token);
} else {
    return false;
}