我正在使用 zend gdata 库编写一个 2 Legged OAuth 应用程序(Google Marketplace 应用程序)。我需要获取谷歌联系人。
代码如下。
require_once 'Zend/Oauth/Consumer.php';
$oauthOptions = array(
'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
'version' => '1.0',
'signatureMethod' => 'HMAC-SHA1',
'consumerKey' => $CONSUMER_KEY,
'consumerSecret' => $CONSUMER_SECRET
);
$consumer = new Zend_Oauth_Consumer($oauthOptions);
$token = new Zend_Oauth_Token_Access();
$httpClient = $token->getHttpClient($oauthOptions);
$url = 'http://www.google.com/m8/feeds/contacts/default/full';
require_once 'Zend/Gdata/Gapps.php';
$gdata = new Zend_Gdata($httpClient);
require_once 'Zend/Gdata/Query.php';
require_once 'Zend/Gdata/Feed.php';
require_once 'Zend/Gdata/App.php';
$query = new Zend_Gdata_Query($url);
try {
$feed = $gdata->getFeed($query);
} catch(Zend_Gdata_App_Exception $ex){
print_r($ex->getMessage());
}
我收到以下错误:
Expected response code 200, got 401
Unknown authorization header
Error 401
执行上述代码时发送的 HTTP 标头是:
GET /m8/feeds/contacts/default/full HTTP/1.1
Host: www.google.com
Connection: close
User-Agent: MyCompany-MyApp-1.0 Zend_Framework_Gdata/1.11.0dev
Accept-encoding: identity
Authorization: OAuth realm="",oauth_consumer_key="686518909188.apps.googleusercontent.com",oauth_nonce="fc99e10f42cdb01c7f3ce1ab2775e616",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1316583946",oauth_version="1.0",oauth_signature="hlbTvPExy4r4%2FyY1ddEsy1AJhf4%3D"
收到的 HTTP 响应:
HTTP/1.1 401 Unknown authorization header
Content-Type: text/html; charset=UTF-8
Date: Wed, 21 Sep 2011 05:45:47 GMT
Expires: Wed, 21 Sep 2011 05:45:47 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Connection: close
<HTML>
<HEAD>
<TITLE>Unknown authorization header</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unknown authorization header</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
请让我知道我在这里缺少什么。