Displaying Feed response

3 views
Skip to first unread message

ravi181229

unread,
Jul 10, 2008, 9:37:47 AM7/10/08
to Google Contacts API
Hi,
I would like to display all emails from my gmail contacts.
I am getting the Feed response.
my code(it displays names):
// Create a Gdata object using the authenticated Http Client
$gdata = new Zend_Gdata($client);
$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/
contacts/me%40gmail.com/full');
$feed = $gdata->getFeed($query);
foreach ($feed as $entry) {
echo $entry->title."<br />";
}

Now I would like to display only emails.

Thanks,
Ravi

Trevor Johns

unread,
Jul 10, 2008, 8:45:35 PM7/10/08
to google-co...@googlegroups.com

Hi Ravi,
Since the Zend_Gdata library doesn't have support for the Contacts API
yet, you'll need to manually extract the contents of the gd:email tag:

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


$feed = $gdata->getFeed($query);
foreach ($feed as $entry) {

// Get contact name
if ($entry->title != "") {
echo $entry->title;
} else {
echo "(Untitled Contact)";
}

// Get all email addresses associated with the contact
echo "<ul>\n";
$emails = $entry->getExtensionElements('gd:email');
foreach ($emails as $email) {
$attributes = $email->getExtensionAttributes();
if (array_key_exists('address', $attributes)) {
echo "<li>" . $attributes['address']['value'] . "</li>\n";
}
}
echo "</ul>\n";

}

--
Trevor Johns

Trevor Johns

unread,
Jul 10, 2008, 9:07:16 PM7/10/08
to google-co...@googlegroups.com
On Thu, Jul 10, 2008 at 5:45 PM, Trevor Johns <tjo...@google.com> wrote:
> Hi Ravi,
> Since the Zend_Gdata library doesn't have support for the Contacts API
> yet, you'll need to manually extract the contents of the gd:email tag:
>
> <snip />

Ravi,
There was an error in the code I just sent. Use this instead:

$gdata = new Zend_Gdata($client);
$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/default/full');
$feed = $gdata->getFeed($query);
foreach ($feed as $entry) {

// Get contact name
if ($entry->title != "") {
echo $entry->title;
} else {
echo "(Untitled Contact)";
}

// Get all email addresses associated with the contact
echo "<ul>\n";

$extensionElements = $entry->getExtensionElements();
foreach ($extensionElements as $extensionElement) {
if ($extensionElement->rootNamespaceURI ==
"http://schemas.google.com/g/2005"
&& $extensionElement->rootElement == "email") {
$attributes = $extensionElement->getExtensionAttributes();

ravi181229

unread,
Jul 11, 2008, 9:14:53 AM7/11/08
to Google Contacts API
Hi Trevor Johns,

Thanks alot.
I followed your code and it really worked fine.

ravi181229

unread,
Jul 14, 2008, 1:51:04 PM7/14/08
to Google Contacts API
Hi Trevor Johns,

I am retrieving single user contact.
I have got the feed as response and now I am trying to display data as
you told me for the previous issue.
but it does not display anything.

my code is:

$gdata = new Zend_Gdata($client);
$feed = $gdata->get('http://www.google.com/m8/feeds/contacts/myemailid
%40gmail.com/full/224320',$client);

foreach ($feed as $entry) {

// Get all email addresses associated with the contact
echo "<ul>\n";
// Get contact name
if ($entry->title != "") {
echo "<li>".$entry->title."</li>";
} else {
echo "<li>(Untitled Contact)</li>";
}
echo "<ul>\n";

// retrieving emails
$extensionElements = $entry->getExtensionElements();
foreach ($extensionElements as $extensionElement) {
if ($extensionElement->rootNamespaceURI ==
"http://schemas.google.com/g/2005"
&& $extensionElement->rootElement == "email") {
$attributes = $extensionElement->getExtensionAttributes();
if (array_key_exists('address', $attributes)) {
echo "<li>" . $attributes['address']['value'] . "</li>\n";
}
}
}
echo "</ul>\n";

echo "</ul>\n";
}

Would you just guide me how to do that.
Thanks for your help.

ravi181229

unread,
Jul 15, 2008, 2:03:07 PM7/15/08
to Google Contacts API
I got solution.

Trevor Johns

unread,
Jul 15, 2008, 6:46:42 PM7/15/08
to google-co...@googlegroups.com
Glad to hear it. :)

--
Trevor Johns

Reply all
Reply to author
Forward
0 new messages