开发者

Specifying Parameters in Zend_GData when using an Oauth Token?

开发者 https://www.devze.com 2022-12-20 12:06 出处:网络
So, I figured out how to get an access token from Google using the Zend_Oauth library in 1.10. Now lets say I want to get my contacts...

So, I figured out how to get an access token from Google using the Zend_Oauth library in 1.10. Now lets say I want to get my contacts...

  $config = array(
      'consumerKey' => 'zzz',
      'signatureMethod' => 'HMAC-SHA1',
'consumerSecret' => 'xxx'
  );

  $token = unserialize($_SESSION['GOOGLE_ACCESS_TOKEN']);


$client = $token->getHttpClient($config);
$client->setMethod(Zend_Http_Client::GET);
// $client->setParameterGet('max-results', '10000');

$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);

$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/default/full');

// $query->MaxResults=100;

$feed = $gdata->getFeed($query);

$feed is a lovely object with 25 contacts. But if I want to get more in a single pull, there doesn't seem to be a way of specifying max results that works.

If I uncomment client->setParameterGet it's ignored. It works if I specify $client->setUri and use $rawdata = client->request() to get the 开发者_运维知识库response, but then other issues crop up with handling the feed data that comes back... like getting it into GData for easy handling.

I've tried $feed = $gdata->importString($rawdata->getBody()) but while $rawdata->getBody() returns what seems to be valid XML, $feed->totalResults throws an error, while it wouldn't if I used $gdata->getFeed($query).

If I uncomment $query->MaxResults=100; use $gdata->getFeed($query) Google returns a 401 with "Unknown authorization header".

So is it possibly to specify parameters while using Zend_GData with an Oauth token? Or am I going to have to build my own requests, then use Zend_Feed (or some other XML/Feed dissector) for parsing?


I totally cannot get the whole list of contacts only 25... parameters do not seem to work using Gdata and query like this:

$http  = $token->getHttpClient($oauthOptions);
$gdata = new Zend_Gdata($http, 'MY APP');
$gdata->setMajorProtocolVersion(3);
$gdata->getHttpClient()->setRequestScheme(Zend_Oauth::REQUEST_SCHEME_QUERYSTRING);


$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/default/full?max-results=10');
$query->setMaxResults(10);
$query->maxResults = 10;
$feed = $gdata->getFeed($query);

so i;m really into finding answers here as well. If either of you gets anything working. please post :-) thanks


It's a bit tricky mixing a process meant to work with AuthSub with OAuth. I did some digging. So far I can get it to download all my contacts like this...

$client = $token->getHttpClient($config);
$client->setMethod(Zend_Http_Client::GET);
$client->setUri('http://www.google.com/m8/feeds/contacts/default/full/');
$client->setParameterGet('max-results', '10000');
$client->setParameterGet('v','3');
$bfeed = $client->request();

Looks like the primary difference between us is I specify the Feed URL in the $client->setUri('http://www.google.com/m8/feeds/contacts/default/full/'); and set my version differently. But I can get the body() property of $bfeed and it gives me 245k of XML to dissect.

My problem is that when I'm pulling down a single contact's feed via this method, I was getting an error.

I, like you, am trying to figure this out, so please reply with anything that works for you.

0

精彩评论

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