Reputation: 12148
The retrieveAllNicknames() function in the Gapps class (pertaining to the Google Provisioning API) returns elements that look like this:
<atom:entry>
<atom:id>
https://apps-apis.google.com/a/feeds/example.com/nickname/2.0/suse
</atom:id>
<atom:category scheme="http://schemas.google.com/g/2005#kind"
term="http://schemas.google.com/apps/2006#nickname"/>
<atom:title type="text">suse</atom:title>
<atom:link rel="self" type="application/atom+xml"
href="https://apps-apis.google.com/a/feeds/example.com/nickname/2.0/suse"/>
<atom:link rel="edit" type="application/atom+xml"
href="https://apps-apis.google.com/a/feeds/example.com/nickname/2.0/suse"/>
<apps:nickname name="suse"/>
<apps:login userName="SusanJones"/>
</atom:entry>
I can write a loop that gets the value of the nickname element like so:
$nicknames = $service->retrieveAllNicknames();
foreach ($nicknames->entries as $entry) {
echo "<p>". $entry->nickname."</p>";
}
How, though, would I access the userName property of the login element? I've tried $entry->login['userName']
, which produces an error message "Cannot use object of type Zend_Gdata_Gapps_Extension_Login as array", and $entry->login
, which I would have expected to work (I don't have to specify the "name" property of the nickname element, so why would I need to specify the userName property of login?) but that one throws this error: "Method Zend_Gdata_Gapps_Extension_Login::__toString() must not throw an exception".
So how do I access that property?
EDIT I've also tried a nested loop through login (assuming there might be more than one per entry) like so:
$nicknames = $service->retrieveAllNicknames();
foreach ($nicknames->entries as $entry) {
$nick = $entry->nickname;
foreach ($entry->login as $loginName) {
$login .= " ".$loginName->userName;
}
echo "<p>".$login." - ". $nick."</p>";
}
That produces "Undefined variable: login in /Applications/MAMP/htdocs/google_api/get_nicknames.php on line 29" over and over (one for each entry) where line 29 is the echo line.
Upvotes: 0
Views: 76
Reputation: 15024
According to the documentation at http://framework.zend.com/manual/en/zend.gdata.gapps.html you can use this code:
$feed = $gdata->retrieveAllNicknames();
foreach ($feed as $nickname) {
echo ' * ' . $nickname->nickname->name . ' => ' .
$nickname->login->username . "\n";
}
Upvotes: 1