Darie Nicolae,

It would seem to me that you don't have an array of values after the
line "$xml = new SimpleXMLElement( $entry->getXML() )", you actually
have SimpleXMLElement object. It only prints like an array when using
print_r because that's the way PHP prints a SimpleXMLElement variable.
Another way of checking this is to use echo( var_dump( $xml ) );. That
prints the type and value of the variable.

Since you have a SimpleXMLElement object, you want to use the
functions at http://us.php.net/manual/en/ref.simplexml.php to parse
the SimpleXMLElement object. The functions "getName", "attributes" and
"children" can be used to trace through the XML doc and extract the
relevant data.

You're at the point where the purpose of your program, and thus what
you do with the returned data, is likely to be very different from
mine. Now that you have the data stored in an object (and you know
there is contact data in there because it printed with print_r), you
don't really need the Google Contacts API to print the information.
There's plenty of documentation on php.net, plus tons of tutorials
around the web, so give it a go.

Good luck,

Greg

On Mar 24, 4:25 pm, darie nicolae <[email protected]> wrote:
> Ok greg, i did as you said
>
> if i  do print_r($xml) i get this :
>
> SimpleXMLElement Object ( [edited] => 2009-03-23T21:51:40.519Z [email]
> => SimpleXMLElement Object ( [...@attributes] => Array ( [rel] 
> =>http://schemas.google.com/g/2005#other[address] => [email protected]
> [primary] => true ) ) [groupMembershipInfo] => Array ( [0] =>
> SimpleXMLElement Object ( [...@attributes] => Array ( [deleted] => false
> [href] 
> =>http://www.google.com/m8/feeds/groups/varzariu.nicolae%40gmail.com/ba...
> ) ) [1] => SimpleXMLElement Object ( [...@attributes] => Array
> ( [deleted] => false [href] 
> =>http://www.google.com/m8/feeds/groups/varzariu.nicolae%40gmail.com/ba...
> ) ) ) ) SimpleXMLElement Object ( [edited] => 2009-03-23T21:36:09.859Z
> [email] => SimpleXMLElement Object ( [...@attributes] => Array ( [rel] 
> =>http://schemas.google.com/g/2005#other[address] => [email protected]
> [primary] => true ) ) [groupMembershipInfo] => Array ( [0] =>
> SimpleXMLElement Object ( [...@attributes] => Array ( [deleted] => false
> [href] 
> =>http://www.google.com/m8/feeds/groups/varzariu.nicolae%40gmail.com/ba...
> ) ) [1] => SimpleXMLElement Object ( [...@attributes] => Array
> ( [deleted] => false [href] 
> =>http://www.google.com/m8/feeds/groups/varzariu.nicolae%40gmail.com/ba...
> ) ) ) )
>
> Now this $xml i need to parse it as array to get the values right? How
> can i do that?
>
> Thanks a lot for helping.
>
> On Mar 24, 9:02 pm, Greg Levine <[email protected]> wrote:
>
> > Yes, all of the contact data is returned with the feed. I think you
> > actually want to run your main foreach routine on $feed, not the XML
> > children. As I understand it, getFeed returns an array of strings
> > containing XML, and each element of the array is its own XML string
> > for an individual contact. So, you have to extract from the array each
> > XML string describing a contact before you convert a string into an
> > XML object. Here's how my code is structured:
>
> > $feed = $gdata->getFeed( $query );
>
> > foreach( $feed as $entry )
> > {
> >      $xml = new SimpleXMLElement( $entry->getXML() );
>
> >      . . .
>
> > }
>
> > Also, I'm using an XML-to-Array parser that I found last year in place
> > of SimpleXML. I would recommend sticking with SimpleXML since it is a
> > legitimate extension of PHP, but in case you want to see the
> > alternative, you can find it 
> > athttp://mysrc.blogspot.com/2007/02/php-xml-to-array-and-backwards.html.
>
> > Hope that helps.
>
> > Greg
>
> > On Mar 24, 1:53 pm, darie nicolae <[email protected]> wrote:
>
> > > Yep everything is clear, my next question is :
>
> > > I did the query, this is the code :
>
> > > $query = new Zend_Gdata_Query("http://www.google.com/m8/feeds/
> > > contacts/" . $username . "/full/?group=" . $grouplink . '&v=2');
> > > $feed = $gdata->getFeed( $query );
>
> > > $xml = new SimpleXMLElement($feed->getXML());
> > > $entries = $xml->children('http://www.w3.org/2005/Atom');
>
> > > foreach ($entries->entry as $entry ) {
>
> > > print_r($entry);
>
> > > The array of entry contains only the name of the contact, but not the
> > > address email and the other details.
> > > Should they be returned on this query, or i need to do another query
> > > based on the contacts name?
>
> > > Thanks for your help.
>
> > > Regards,
> > > Darie Nicolae
>
> > > On Mar 24, 7:19 pm, Greg Levine <[email protected]> wrote:
>
> > > > Sorry for not clarifying. If you just recently downloaded Zend Gdata,
> > > > then you should have the latest version. You can read about specifying
> > > > a version 
> > > > athttp://code.google.com/apis/contacts/docs/2.0/developers_guide_protoc....
>
> > > > I read "every request that you send using the Contacts Data API should
> > > > specify version 2 of the API" to mean that while all functionality of
> > > > version 1 remains in version 2, you need to specify that you are using
> > > > version 2 in order to take advantage of the enhancements the most
> > > > recent version provides. If anyone out there knows better than me (and
> > > > I'm sure there are plenty), then please correct me if I'm wrong.
>
> > > > While the HTTP header method is preferred, I wasn't doing anything too
> > > > complex. So, I just tacked "v=2" onto the end of all of my query
> > > > URI's. In your case, it would look like the following:
>
> > > > $query = new Zend_Gdata_Query( "http://www.google.com/m8/feeds/
> > > > contacts/default/full?group=http://www.google.com/m8/feeds/groups/user
> > > > %40gmail.com/base/2842a9b10e7d48bb&v=2" );
>
> > > > Notice the "&v=2" after the group query string value? That's all it
> > > > takes to specify version 2.
>
> > > > Greg
>
> > > > On Mar 24, 10:35 am, darie nicolae <[email protected]> wrote:
>
> > > > > Hey Greg,
>
> > > > > Thanks for replying so fast. By version 2 you mean the version two of
> > > > > the Zend Gdata?
>
> > > > > On Mar 24, 4:24 pm, Greg Levine <[email protected]> wrote:
>
> > > > > > darie nicolae,
>
> > > > > > You're just a little off with your contacts query. All you need to 
> > > > > > do
> > > > > > is change "groups" to "contacts" in the URI. When you query for
> > > > > > groups, you are telling the API that you want to look for a groups
> > > > > > feed. To query for contacts, you need to tell the API that you want 
> > > > > > to
> > > > > > look for a contacts feed. You should leave the group query parameter
> > > > > > URI exactly as is.
>
> > > > > > Also,  note that I had more success with version 2 requests. For one
> > > > > > thing, I think the groups query required version 2. And for another,
> > > > > > you don't need to specify max results, since that property doesn't
> > > > > > seem to exist in version 2.
>
> > > > > > Best of luck,
> > > > > > Greg
>
> > > > > > On Mar 23, 6:18 pm, darie nicolae <[email protected]> wrote:
>
> > > > > > > Hello, i have one question regarding the same topic. After i made 
> > > > > > > a
> > > > > > > query to get the groups i got something like this :
>
> > > > > > >http://www.google.com/m8/feeds/groups/user%40gmail.com/base/2842a9b10...
>
> > > > > > > Now in order to get the contacts from this group, the query needs 
> > > > > > > to
> > > > > > > be :
>
> > > > > > > $query = new 
> > > > > > > Zend_Gdata_Query("http://www.google.com/m8/feeds/groups/
> > > > > > > default/full/?group=http://www.google.com/m8/feeds/groups/user
> > > > > > > %40gmail.com/base/2842a9b10e7d48bb");
>
> > > > > > > or it should be directly : 
> > > > > > > Zend_Gdata_Query("http://www.google.com/m8/
> > > > > > > feeds/groups/user%40gmail.com/base/2842a9b10e7d48bb"); ?
>
> > > > > > > I dont get any response in both ways.
>
> > > > > > > On Mar 23, 5:55 pm, cwood <[email protected]> wrote:
>
> > > > > > > > Greg-
>
> > > > > > > > Try using the whole group id (url-encoded) in your query, like 
> > > > > > > > this:
>
> > > > > > > >http://www.google.com/m8/feeds/contacts/user%40gmail.com/full/?group=...
>
> > > > > > > > Regards,
> > > > > > > > Charlie
> > > > > > > > Spanning Sync
>
> > > > > > > > On Mar 23, 10:25 am, Greg Levine <[email protected]> wrote:
>
> > > > > > > > > Okay, it's been two days of trying a number of different 
> > > > > > > > > things to
> > > > > > > > > make this work, but I can't seem to figure it out. (Note: I'm 
> > > > > > > > > using
> > > > > > > > > PHP.)
>
> > > > > > > > > I'm able to retrieve a list of groups without any trouble. 
> > > > > > > > > Then, using
> > > > > > > > > a group ID that is returned, I want to query for the contacts 
> > > > > > > > > in that
> > > > > > > > > group. Let's say that group ID 
> > > > > > > > > ishttp://www.google.com/m8/feeds/groups/user%40gmail.com/base/6.
> > > > > > > > > I may need to do some work on the URI to make sure the query 
> > > > > > > > > string is
> > > > > > > > > properly formed, but the code I have (so far) is:
>
> > > > > > > > > try
> > > > > > > > > {
> > > > > > > > >         $gdata = new Zend_Gdata( $httpClient );
> > > > > > > > >         $query = new Zend_Gdata_Query( 
> > > > > > > > > "http://www.google.com/m8/feeds/
> > > > > > > > > contacts/user%40gmail.com/full/?group=6&v=2" ); // I've tried 
> > > > > > > > > it
> > > > > > > > > without the "v" query parameter too.
> > > > > > > > >         $feed = $gdata->getFeed( $query );
> > > > > > > > >         print_r( feed );}
>
> > > > > > > > > catch( Exception $e )
> > > > > > > > > {
> > > > > > > > >         echo( $e->getMessage() );
>
> > > > > > > > > }
>
> > > > > > > > > It would seem that would work because I can replace the
> > > > > > > > > Zend_Gdata_Query parameter with 
> > > > > > > > > "http://www.google.com/m8/feeds/
> > > > > > > > > contacts/user%40gmail.com/full" and print a complete list of 
> > > > > > > > > my
> > > > > > > > > contacts, without any restraints or restrictions. So, I'm not 
> > > > > > > > > really
> > > > > > > > > sure what I'm doing differently. Or, what I'm supposed to do
> > > > > > > > > differently to print a list of contacts from a specific 
> > > > > > > > > group. I've
> > > > > > > > > spent a lot of time, specifically 
> > > > > > > > > withhttp://code.google.com/apis/contacts/docs/2.0/reference.html#Parameters,
> > > > > > > > > trying to come up with a solution. But, it's been to no 
> > > > > > > > > avail. Using
> > > > > > > > > the above code, I keep receiving "Expected response code 200, 
> > > > > > > > > got 400
> > > > > > > > > Invalid value for group parameter: 6" as the exception. Using
> > > > > > > > > variations, I've also received "404 Group not found" on 
> > > > > > > > > occasion. Any
> > > > > > > > > help is much is appreciated.
>
> > > > > > > > > Thanks,
>
> > > > > > > > > Greg
>
> > > > > > > > > On Mar 21, 2:29 am, Greg Levine <[email protected]> wrote:
>
> > > > > > > > > > Sorry for cluttering up this discussion group. I was able 
> > > > > > > > > > to figure
> > > > > > > > > > out the answer.
>
> > > > > > > > > > It turns out that I only need to specify version 2 of the 
> > > > > > > > > > API in the
> > > > > > > > > > query.
>
> > > > > > > > > > $query = new Zend_Gdata_Query( 
> > > > > > > > > > "http://www.google.com/m8/feeds/groups/
> > > > > > > > > > default/full?v=2" );
>
> > > > > > > > > > And once I was using version 2, I had to remove the 
> > > > > > > > > > setMaxResults
> > > > > > > > > > line. That did it.
>
> > > > > > > > > > On another note, does anyone know how to get the e-mail 
> > > > > > > > > > address and/or
> > > > > > > > > > nickname of the
>
> ...
>
> read more »
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Contacts API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-contacts-api?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to