Contact API In PHP

120 views
Skip to first unread message

vks

unread,
Jan 14, 2009, 11:44:54 PM1/14/09
to Google Contacts API
Hi,
I have tried this code

<?php
set_include_path('/home/jwitt/public_html/grabber');
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Gapps');
Zend_Loader::loadClass('Zend_Gdata_Query');

// Using Client Login
$client = Zend_Gdata_ClientLogin::getHttpClient("vksh...@gmail.com",
"*******", "cp");
$gdata = new Zend_Gdata($client);
$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/
contacts/
USER%40domain.com/full');
/*$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/
contacts/
default/full'); */
$query->setMaxResults(100);
$feed = $gdata->getFeed($query);

foreach ($feed as $entry) {
$XMLContent = $entry->getXML();
print_r( $XMLContent );

}
?>

for fetching contacts of the given client but i got the following
errors

Fatal error: Uncaught exception 'Zend_Uri_Exception' with message
'Invalid URI supplied' in /home/jwitt/public_html/grabber/Zend/Uri/
Http.php:156 Stack trace: #0 /home/jwitt/public_html/grabber/Zend/
Uri.php(132): Zend_Uri_Http->__construct('http', '//www.google.co...')
#1 /home/jwitt/public_html/grabber/Zend/Http/Client.php(257):
Zend_Uri::factory('http://www.goog...') #2 /home/jwitt/public_html/
grabber/Zend/Gdata/App.php(618): Zend_Http_Client->setUri('http://
www.goog...') #3 /home/jwitt/public_html/grabber/Zend/Gdata.php(202):
Zend_Gdata_App->performHttpRequest('GET', 'http://www.goog...', Array,
NULL, NULL, NULL) #4 /home/jwitt/public_html/grabber/Zend/Gdata/App.php
(762): Zend_Gdata->performHttpRequest('GET', 'http://www.goog...',
Array) #5 /home/jwitt/public_html/grabber/Zend/Gdata/App.php(685):
Zend_Gdata_App->get('http://www.goog...', Array) #6 /home/jwitt/
public_html/grabber/Zend/Gdata/App.php(193): Zend_Gdata_App->importUrl
('http://www.goog...', 'Zend_Gdata_Feed') #7 /home/jwitt/public_html/
grabber/Zend/Gdata.php( in /home/jwitt/public_html/grabber/Zend/Uri/
Http.php on line 156

anyone know the reason please help.

Thanks,
VKS

Julian (Google)

unread,
Jan 16, 2009, 6:35:59 AM1/16/09
to Google Contacts API
Hi,

I think the problem is on the Path, it should include /Zend, also, you
need to load Zend_Gdata_Gapps:

<?php

$clientLibraryPath = '/path/to/Zend';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR .
$clientLibraryPath); // to keep old path.

require_once 'Loader.php';

Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Gapps');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');

$client = Zend_Gdata_ClientLogin::getHttpClient
("us...@domain.com","PASSWORD", "cp");
$gdata = new Zend_Gdata($client);
$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/
default/full');

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

foreach ($feed as $entry) {
$XMLContent = $entry->getXML();
print_r( $XMLContent );
}

?>

Cheers,
Julian.

On Jan 15, 4:44 am, vks <vkshi...@gmail.com> wrote:
> Hi,
> I have tried this code
>
> <?php
> set_include_path('/home/jwitt/public_html/grabber');
> require_once 'Zend/Loader.php';
> Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
> Zend_Loader::loadClass('Zend_Gdata_Gapps');
> Zend_Loader::loadClass('Zend_Gdata_Query');
>
> // Using Client Login
> $client = Zend_Gdata_ClientLogin::getHttpClient("vkshi...@gmail.com",
> "*******", "cp");
> $gdata = new Zend_Gdata($client);
> $query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/
> contacts/
> USER%40domain.com/full');
> /*$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/
> contacts/
> default/full'); */
> $query->setMaxResults(100);
> $feed = $gdata->getFeed($query);
>
> foreach ($feed as $entry) {
>   $XMLContent = $entry->getXML();
>   print_r( $XMLContent );
>
> }
>
> ?>
>
> for fetching contacts of the given client but i got the following
> errors
>
> Fatal error: Uncaught exception 'Zend_Uri_Exception' with message
> 'Invalid URI supplied' in /home/jwitt/public_html/grabber/Zend/Uri/
> Http.php:156 Stack trace: #0 /home/jwitt/public_html/grabber/Zend/
> Uri.php(132): Zend_Uri_Http->__construct('http', '//www.google.co...')
> #1 /home/jwitt/public_html/grabber/Zend/Http/Client.php(257):
> Zend_Uri::factory('http://www.goog...') #2 /home/jwitt/public_html/
> grabber/Zend/Gdata/App.php(618): Zend_Http_Client->setUri('http://www.goog...') #3 /home/jwitt/public_html/grabber/Zend/Gdata.php(202):

My Mobzz

unread,
Jan 16, 2009, 8:03:10 AM1/16/09
to google-co...@googlegroups.com
Hi - this is interesting, and I think I might want to try it.  But - I'm new at this and want to make sure I understand which portions of this code I'd really need to replace or update before giving it a try.
 
1. I need to make sure ZEND is installed.
2. '/path/to/Zend' in your first sentence from the script - I need to translate to whatever my actual path info is for ZEND
3.  I need to value PATH_SEPARATOR
4.  The first 2 parameters inside the parens for this statement must be replaced with real values:
$client = Zend_Gdata_ClientLogin::getHttpClient ("us...@domain.com","PASSWORD", "cp");
 
Do I have it right?
 
Thank you, Julian.
 
Gary

Julian (Google)

unread,
Jan 16, 2009, 8:49:35 AM1/16/09
to Google Contacts API
Hi Gary,

PATH_SEPARATOR is a PHP constant, you don't need to change it:
http://uk3.php.net/set_include_path

Everything else sounds right.

Cheers,
Julian.

On Jan 16, 1:03 pm, My Mobzz <mymo...@gmail.com> wrote:
> Hi - this is interesting, and I think I might want to try it.  But - I'm new
> at this and want to make sure I understand which portions of this code I'd
> really need to replace or update before giving it a try.
>
> 1. I need to make sure ZEND is installed.
> 2. '/path/to/Zend' in your first sentence from the script - I need to
> translate to whatever my actual path info is for ZEND
> 3.  I need to value PATH_SEPARATOR
> 4.  The first 2 parameters inside the parens for this statement must be
> replaced with real values:
> $client = Zend_Gdata_ClientLogin::getHttpClient ("u...@domain.com","PASSWORD",
> "cp");
>
> Do I have it right?
>
> Thank you, Julian.
>
> Gary
>
> On 1/16/09, Julian (Google) <j...@google.com> wrote:
>
>
>
> > Hi,
>
> > I think the problem is on the Path, it should include /Zend, also, you
> > need to load Zend_Gdata_Gapps:
>
> > <?php
>
> > $clientLibraryPath = '/path/to/Zend';
> > $oldPath = set_include_path(get_include_path() . PATH_SEPARATOR .
> > $clientLibraryPath); // to keep old path.
>
> > require_once 'Loader.php';
>
> > Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
> > Zend_Loader::loadClass('Zend_Gdata_Gapps');
> > Zend_Loader::loadClass('Zend_Gdata_Query');
> > Zend_Loader::loadClass('Zend_Gdata_AuthSub');
>
> > $client = Zend_Gdata_ClientLogin::getHttpClient
> > ("u...@domain.com","PASSWORD", "cp");
Reply all
Reply to author
Forward
0 new messages