0

在进行简单的日历获取时收到以下错误:

Expected response code 200, got 403
Version 3.0 is not supported.

代码如下:

认证

$options = array(
    'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
    'version' => '1.0',
    'signatureMethod' => 'HMAC-SHA1',
    'consumerKey' => $config['consumer_key'],
    'consumerSecret' => $config['consumer_secret']
);

/**
 * Create HTTP Client object which adds OAuth Authorization
 * headers to outbound requests.
 */
$this->_consumer = new Zend_Oauth_Consumer($options);
$this->_token = new Zend_Oauth_Token_Access();
$this->_http_client = $this->_token->getHttpClient($options);

日历查询

$calendarClient = new Zend_Gdata_Calendar(Oauth::I()->getHttpClient());
print $calendarClient->getMajorProtocolVersion();

$query = $calendarClient->newEventQuery();
$query->setUser('default');
$query->setVisibility('private');
$query->setProjection('full');

Oauth::I()->setRequestorId($query);
try {
  $list = $calendarClient->getCalendarEventEntry($query);
  var_dump($list);
} catch(Exception $e) {
  var_dump($e->getMessage());
}
var_dump($calendarEventsFeed);

在 Zend_Http_Client_Adapter_Socket 资源头下转储 $calenderClient 时:

  ["gdata-version"]=>
  array(2) {
    [0]=>
    string(13) "GData-Version"
    [1]=>
    string(3) "3.0"
  }

但是 getMajorProtocolVersion() 返回 1。

4

1 回答 1

0

解决方案是在您需要更改 GData 版本时在 HTTP 客户端上设置标头()。我确信有专门针对此的方法,但这有效。

// $http_client is Zend_Oauth_Token_Access()::getHttpClient()
$http_client->setHeaders('GData-Version', '2.0');
于 2012-05-23T06:46:59.463 回答