Get Group Members using PHP

187 views
Skip to first unread message

Oscar Valenzuela

unread,
Jun 6, 2008, 5:44:58 PM6/6/08
to google-co...@googlegroups.com
Hi, i was trying to get the Group for some contacts, somebody try
this?

I am using PHP, and create a code based on some others on the list.

<?

ini_set('include_path', $extLibPath);

include_once('Zend/Loader.php');

Zend_Loader::registerAutoload();

$mail = "email";

$pass = 'password';

$service = 'cp';

$client = Zend_Gdata_ClientLogin::getHttpClient($mail, $pass,
$service);


/*

$googleUri = Zend_Gdata_AuthSub::getAuthSubTokenUri('http://'.
$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'],urlencode($scope), 0,
1);

echo "Click <a href='$googleUri'>here</a> to authorize this
application.";

*/

function GetAllContacts($client,$mail){
$scope = "http://www.google.com/m8/feeds/contacts/".$mail."/";

$gdata = new Zend_Gdata($client);

$query = new Zend_Gdata_Query($scope.'base');

$query->setMaxResults(10000);

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

foreach ($feed as $entry){

echo "<br><br>";

echo $entry->title->text."=>";

$ext = $entry->getExtensionElements();

foreach($ext as $extension){

if($extension->rootElement == "email"){

$attr=$extension->getExtensionAttributes();

echo $attr['address']['value']."<br>";

}
if($extension->rootElement == "phoneNumber"){
echo $extension->text."<br>";

}
if($extension->rootElement == "postalAddress"){
echo $extension->text."<br>";

}

}

}
}

function GetAllContactsGroups($client,$mail){
$scope = "http://www.google.com/m8/feeds/groups/".$mail."/";

$gdata = new Zend_Gdata($client);

$query = new Zend_Gdata_Query($scope.'full');

$query->setMaxResults(10000);

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

foreach ($feed as $entry){

echo "<br><br>";

echo $entry->title->text."=>";
echo $entry->id->text."=>";

}

}

?>

This work really great form me, and i can get the Grroups and
Contacts, but i can't get more info to know on what Group is a
Contact.

If somebody could help, i really appreciate..

:D

Oscar Valenzuela B.

Jeff S

unread,
Jun 9, 2008, 12:22:44 PM6/9/08
to Google Contacts API
Hi Oscar,

Thank you for sharing your code! If you want to find out which
contacts are in a group, or which groups a contact belongs to, you can
look at the gContact:groupMembershipInfo element in a contact entry.
(Note that gContact is a namespace alias for http://schemas.google.com/contact/2008
) When you find a groupMembershipInfo element, it will contain the URL
of the Atom entry which represents that group. Does this make sense?

(See the example here: http://code.google.com/apis/contacts/developers_guide_protocol.html#retrieving_without_query
)

Happy coding,

Jeff

On Jun 6, 2:44 pm, "Oscar Valenzuela" <oscar.valenzuel...@gmail.com>
wrote:

Oscar Valenzuela

unread,
Jun 9, 2008, 4:48:42 PM6/9/08
to google-co...@googlegroups.com
Hi Jeff, thanks for answer.

The true is that i am very very new with this technology, so i must
confes that i didnt understand what you said.
I var dump the responses and i dont get that entry.
I must ask to another scope or something like that?

Thanks a lot again

2008/6/9 Jeff S <j...@google.com>:

--
Saludos Cordiales.


Oscar Valenzuela B. (http://ovalenzuela.gnuchile.cl)
Presidente Ejecutivo (ovale...@gnuchile.cl)
Fundación de Desarrollo Tecnológico Libre
FSF LATIN AMERICAN BOARD MEMBER
Comunidad Chilena GNU (www.gnuchile.cl)

--------------------------------------------------
Por favor ayudanos a proteger tu libertad!.
Unase hoy y haga la diferencia, cada miembro cuenta!
Realice una donación a la Fundación GNUCHILE.

Reply all
Reply to author
Forward
0 new messages