Details
-
Type:
Sub-task
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.5.0
-
Fix Version/s: 1.10.1
-
Component/s: Zend_Gdata
-
Labels:None
Description
GData Ignores my parameters (max-results, start-index etc) when fetching feeds.
No matter what parameter values I add, the GData cbntacts feed always returns the same data set (first 25 entries)
Here's my code:
<?php
session_start();
//header("Content-type: text/xml");
require_once 'Zend/Oauth/Consumer.php';
require_once 'Zend/Crypt/Rsa/Key/Private.php';
require_once 'Zend/Gdata/ClientLogin.php';
require_once 'Zend/Gdata.php';
$users_index = $_SESSION['users_index'];
// my rsa key string. when in production, put this string in an
external file and call it using get_file_contents
$test_cert = <<<_CERT
----BEGIN RSA PRIVATE KEY----
sadfdsfsdfdsfsdfsdfsdsdfsdfsdfsdfsdfsd
----END RSA PRIVATE KEY----
_CERT;
$options = array(
'requestScheme' => Zend_Oauth::REQUEST_SCHEME_QUERYSTRING,
'version' => '1.0',
'signatureMethod' => 'RSA-SHA1',
'callbackUrl' => 'http://www.mydomain.com/act/test', // UPDATE FOR
YOUR DETAILS
'requestTokenUrl' => 'https://www.google.com/accounts/
OAuthGetRequestToken',
'userAuthorisationUrl' => 'https://www.google.com/accounts/
OAuthAuthorizeToken',
'accessTokenUrl' => 'https://www.google.com/accounts/
OAuthGetAccessToken',
'consumerKey' => 'www.mydomain.com', // UPDATE FOR YOUR DETAILS
'consumerSecret' => new Zend_Crypt_Rsa_Key_Private($test_cert)
);
/**
- Example utilises the Google Contacts API
*/
$consumer = new Zend_Oauth_Consumer($options);
if (!isset($_SESSION['ACCESS_TOKEN_GOOGLE'])) {
if (!empty($_GET)) {
// Google does not like empty POST bodies - switch to GET
$token = $consumer->getAccessToken($_GET,
unserialize($_SESSION['REQUEST_TOKEN_GOOGLE']), Zend_Oauth::GET);
$_SESSION['ACCESS_TOKEN_GOOGLE'] = serialize($token);
} else {
// Default POST works fine here since POST body contains scope
parameter
$token = $consumer->getRequestToken(array('scope'=>'http://
www.google.com/m8/feeds'), Zend_Oauth::GET);
$_SESSION['REQUEST_TOKEN_GOOGLE'] = serialize($token);
$consumer->redirect();
exit;
}
} else {
$token = unserialize($_SESSION['ACCESS_TOKEN_GOOGLE']);
$_SESSION['ACCESS_TOKEN_GOOGLE'] = null;
}
// OAuth Access Token Retreived; Proceed to query Data API
$client = $token->getHttpClient($options);
//$client->setUri('http://www.google.com/m8/feeds/groups/default/
full');
//$client->setMethod(Zend_Http_Client::GET);
$contact = new Zend_Gdata($client);
$contact_count =0;
$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/
default/full');
$feed = $contact->getFeed($query);
$name = "";
$email = "";
$db = new db_connect();
$db = $db->db;
foreach($feed as $entry){
$name = $entry->title;
$parts = $entry->getExtensionElements();
foreach($parts as $p){
$element = $p->getDOM();
switch($element->tagName){
case 'email':
$email = $element->getAttribute('address');
break;
default:
continue;
}
}
$data = array(
'name' => "$name",
'email' => "$email",
'users_index' => $users_index
);
//insert into DB here
$contact_count++;
}
This is being caused by Zend_Oauth_client not preserving query parameters on a GET request.
Attached ZF-4158_v1.patch
as a patch to fix this behavior, to be sent to
Pádraic Brady for review.