Get ALL photos from a facebook album (PHP API) - php

I've got a problem with my source code. I've don't used since... 8/9 months and now, it doesn't work anymore.
I'm looking to list all my photos in my albums BUT, now it's listing me just 25 photos of each album and not more. I've got 100/200/250 photos per albums (party shootings) and I want to list them for my own website (to use Facebook bandwidth)
Here is my source code :
<?php
ob_start();
session_start();
include_once('facebook.php');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Albums</title>
</head>
<body>
<?php
$params = array(
'appId' => APP_ID,
'secret' => APP_SECRET,
);
$facebook = new Facebook($params);
$user = $facebook->getUser();
$log = null;
if ($user) {
$log = $facebook->getLogoutUrl();
} else {
$log = $facebook->getLoginUrl(array('scope' => 'user_photos'));
}
echo '' . (($user) ? 'logout' : 'login') . '';
if ($user) {
$data = $facebook->api(
'/me/albums',
'GET',
array(
'fields' => 'id,name,privacy,photos.fields(id,name,images)',
'limit' => '300'
)
);
foreach ($data['data'] as $album) {
echo '<div>';
echo '<h3>' . $album['name'] . ' ' . $album['privacy'] . '</h3>';
echo '<textarea style="width: 800px; height: 500px;">';
foreach ($album['photos']['data'] as $photo) {
echo $photo['images'][0]['source'].'';
}
echo '</textarea>';
echo '<textarea style="width: 800px; height: 500px;">';
foreach ($album['photos']['data'] as $photo) {
echo $photo['images'][7]['source'].'';
}
echo '</textarea>';
echo '</div>';
//break;
}
}
?>
</body>
</html>
<?php ob_flush(); ?>
So if you're testing this code, you'll see that it listing to you all your albums but not all the pictures, it stops to 25.

Looks like you use limit in the wrong place. Try-
$data = $facebook->api(
'/me/albums',
'GET',
array(
'fields' => 'id,name,privacy,photos.fields(id,name,images).limit(300)',
'limit' => '50'
)
);
In this case, FB will limit your albums to 50 and the photos within your albums to 300.

Related

Wordpress theme fatal error "Fatal error: Call to undefined method WP_Error::get_items()"

One of my Wordpress themes is showing the following error:
Fatal error: Call to undefined method WP_Error::get_items() in /home1/mywebsite/public_html/learnphp123.com/wp-content/themes/econews/admin/IDE_admin.php on line 88
The code for the file is (you can see "get_items()" on line 88 .... actually the third line in the code):
if($feed) {
$html = '<ul>';
foreach ($feed->get_items() as $item){
$html.="<li><span>".$item->get_date('d M Y')."</span> ".$item->get_title()."</li>";
}
Can anybody tell me what to use in the place of "get_items()"?
Thank you very much for your help!
The total code of the file is given below and I am only getting the error on line 88 related to feed get_items ().
<?php
/*
Copyright 2010, idesigneco.com
http://idesigneco.com
*/
define('IDE_ADMIN_FEED', 'http://idesigneco.com/wp_pub.php?id=ide_admin_newsfeed.xml&theme='.IDE_CODE.'&ver='.IDE_VERSION);
// load form generator and validator
include IDE_ADMIN_PATH.'IDE_FormGenerator.class.php';
// initialize the admin form
$Form = new IDE_FormGenerator(array(
'name' => 'admin',
'method' => 'post',
'action' => ''
));
// setup the form fields
$Form->elements(
null,
array(
'admin_action' => array(
'type' => 'hidden', 'value' => 'admin',
'error' => 'Your settings have been updated.'
)
)
);
// load theme specific options
include IDE_ADMIN_PATH.'/IDE_admin_options.php';
$Form->elements(
null,
array(
'submit' => array(
'type' => 'submit', 'value' => 'Save', 'label' => ''
),
)
);
$Form->printErrors(true);
// ________________________________________________________
// process the form data
if(!empty($_POST['admin_action'])) {
// unchecked checkbox options don't show up, so fill them with predefined key names
ide_save_options( array_merge( array_fill_keys($IDE_checkboxes, ''),
stripslashes_deep($_POST)
)
);
$Form->setErrors(array('admin_action'));
}
// ________________________________________________________
// populate the form with saved options
$Form->data($IDE_options);
// ________________________________________________________
// print out the admin area
ide_admin_header();
$Form->generate();
ide_admin_footer();
// ________________________________________________________
// idesigneco news feed
function ide_admin_news() {
$time = ide_option('admin_newsfeed_time');
$html = ide_option('admin_newsfeed');
// feed expired, update
if(!$html || !$time || ($time+(5*3600)) < time() ) {
if(function_exists('fetch_feed')){
$feed = fetch_feed(IDE_ADMIN_FEED);
if($feed) {
$html = '<ul>';
foreach ($feed->get_items() as $item){
$html.="<li><span>".$item->get_date('d M Y')."</span> ".$item->get_title()."</li>";
}
$html.= '</ul>';
} else {
$html = 'Updates unavailable at this time';
}
} else {
// deprecated feed api
if(function_exists('fetch_rss')){
include_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss(IDE_ADMIN_FEED);
$html = '<ul>';
foreach ($rss->items as $item){
$html.="<li><span>".date('d M Y', strtotime($item['pubdate']))."</span> ".$item['title']."</li>";
}
$html.= '</ul>';
}
}
ide_save_option('admin_newsfeed_time', time());
ide_save_option('admin_newsfeed', $html);
}
echo $html;
}
// admin header
function ide_admin_header() {
?>
<div id="ide_admin">
<div class="left">
<h1 class="ide_title"><?php echo IDE_NAME.' '.IDE_VERSION; ?></h1>
<div class="clear"> </div>
<?php
}
// admin footer
function ide_admin_footer() {
?>
</div><!-- left //-->
<div class="right">
<div class="idesigneco">
<img src="<?php echo IDE_ADMIN_STATIC.'/idesigneco.png'; ?>" alt="Theme by iDesignEco" title="Theme by iDesignEco" />
</div>
<div class="news">
<h2>iDesignEco Updates</h2>
<?php ide_admin_news(); ?>
</div>
</div><!-- right //-->
<div class="clear"> </div>
</div><!-- ide_admin //-->
<?php
}
?>
This probably happens when getting data for $feed fails, so it becomes WP_Error class that does not have get_items() method. Try to modify the code like this:
if (! is_wp_error( $feed )) {
$html = '<ul>';
foreach ($feed->get_items() as $item){
$html.="<li><span>".$item->get_date('d M Y')."</span> ".$item->get_title()."</li>";
}
UPDATE:
Just as I assumed, the $feed gets its data from fetch_feed(), so the solution should still be to replace:
if($feed) {
with:
if (! is_wp_error( $feed )) {

Pulling in categories on eBay using XML API

Long time lurking first time posting, I am stumped!
I have been attempting to get a dynamic category list on my employers eBay shop for a while now, I have spent a lot of time trawling for answers or pre-written code but came to the conclusion that if I want it done I'm going to have to do it myself (totally fine but time consuming).
Playing with the eBay Dev API testing ground I have managed to pull down the categories that I want. What I am finding difficult is how to then style and organize the results.
This would be easier if I could target the tags that the XML outputs with CSS but as they are non-standard, I can't.
This is what I have written so far, the 'style color:red' was simply to test the div was working and all the required credentials are stored in the 'keys.php' file:
<?php
/* © 2013 eBay Inc., All Rights Reserved */
/* Licensed under CDDL 1.0 - http://opensource.org/licenses/cddl1.php */
require_once('keys.php') ?>
<?php require_once('eBaySession.php') ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<TITLE>GetCatagories</TITLE>
<style type="text/css">
#child {
color:red;
}
</style>
</HEAD>
<BODY>
<?php
//SiteID must also be set in the Request's XML
//SiteID = 3 (US) - UK = 3, Canada = 2, Australia = 15, ....
//SiteID Indicates the eBay site to associate the call with
$siteID = 3;
//the call being made:
$verb = 'GetStore';
//Level / amount of data for the call to return (default = 0)
$detailLevel = 0;
///Build the request Xml string
$requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
$requestXmlBody .= '<GetStoreRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
$requestXmlBody .= "<RequesterCredentials><eBayAuthToken>$userToken</eBayAuthToken></RequesterCredentials>";
$requestXmlBody .= '</GetStoreRequest>';
//Create a new eBay session with all details pulled in from included keys.php
$session = new eBaySession($userToken, $devID, $appID, $certID, $serverUrl, $compatabilityLevel, $siteID, $verb);
//send the request and get response
$responseXml = $session->sendHttpRequest($requestXmlBody);
if(stristr($responseXml, 'HTTP 404') || $responseXml == '')
die('<P>Error sending request');
//Xml string is parsed and creates a DOM Document object
$responseDoc = new DomDocument();
$responseDoc->loadXML($responseXml);
//get any error nodes
$errors = $responseDoc->getElementsByTagName('Errors');
//if there are error nodes
if($errors->length > 0)
{
echo '<P><B>eBay returned the following error(s):</B>';
//display each error
//Get error code, ShortMesaage and LongMessage
$code = $errors->item(0)->getElementsByTagName('ErrorCode');
$shortMsg = $errors->item(0)->getElementsByTagName('ShortMessage');
$longMsg = $errors->item(0)->getElementsByTagName('LongMessage');
//Display code and shortmessage
echo '<P>', $code->item(0)->nodeValue, ' : ', str_replace(">", ">", str_replace("<", "<", $shortMsg->item(0)->nodeValue));
//if there is a long message (ie ErrorLevel=1), display it
if(count($longMsg) > 0)
echo '<BR>', str_replace(">", ">", str_replace("<", "<", $longMsg->item(0)->nodeValue));
}
else //no errors
{
$i = 2;
while ($i <= 188) {
echo '<div id="catagories">';
echo $responseDoc->getElementsByTagName("Name")->item($i++)- >textContent;
echo '<BR>';
echo '</div>';
}
}
?>
</BODY>
</HTML>
The majority of the above code is credential checking and error management it's really the last 12 or so lines of code that do the heavy lifting.
Currently it has output all of my categories and the corresponding child categories in one long vertical list, ideally I would like to indent the children and give them a smaller font-size, the easiest way (to my mind) would have been to div them out and apply CSS but I'm beginning to think there is an easier way, any suggestions or comments are welcome at this point,
Thank you for any help in advance
If you are happy to use Composer in your project I have developed an SDK for PHP that simplifies using the API. The example below will get the store categories in the correct order and output a simple tree using nested <ol> elements which can be styles using CSS.
<?php
require __DIR__.'/vendor/autoload.php';
use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;
use \DTS\eBaySDK\Trading\Enums;
$service = new Services\TradingService([
'credentials' => [
'appId' => $appID,
'devId' => $devID,
'certId' => $certID
],
'authToken' => $userToken,
'siteId' => Constants\SiteIds::GB
]);
$request = new Types\GetStoreRequestType();
$request->CategoryStructureOnly = true;
$response = $service->getStore($request);
$html = '';
if (isset($response->Errors)) {
$html .= '<p>eBay returned the following error(s):<br/>';
foreach ($response->Errors as $error) {
$html .= sprintf(
"%s: %s<br/>%s<br/>",
$error->SeverityCode === Enums\SeverityCodeType::C_ERROR ? 'Error' : 'Warning',
htmlentities($error->ShortMessage),
htmlentities($error->LongMessage)
);
}
$html .= '</p>';
}
if ($response->Ack !== 'Failure') {
$categories = iterator_to_array($response->Store->CustomCategories->CustomCategory);
usort($categories, 'sortCategories');
foreach ($categories as $category) {
$html .= '<ol>'.buildCategory($category).'</ol>';
}
}
function buildCategory($category)
{
$html = '<li>';
$html .= htmlentities($category->Name);
$children = iterator_to_array($category->ChildCategory);
usort($children, 'sortCategories');
foreach ($children as $child) {
$html .= '<ol>'.buildCategory($child).'</ol>';
}
$html .= '</li>';
return $html;
}
function sortCategories($a, $b)
{
if ($a->Order === $b->Order) {
return 0;
}
return ($a->Order < $b->Order) ? -1 : 1;
}
echo <<< EOF_HTML
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Example</title>
<style>
ol {
list-style-type: none;
}
</style>
</head>
<body>
$html
</body>
</html>
EOF_HTML;

PHP + CSS: Output Options Framework Content

Two questions from a coding ub3r n00b...
Firstly, I'm using the Options Framework Theme by Devin Price and just wanting to know how would I output the background property in the <head> section of my header.php file, from the Theme Options page only if the user has uploaded an image or chosen a color for this?
My options.php:
$options[] = array(
'name' => __('Background', 'options_framework_theme'),
'desc' => __('Add a background.', 'options_framework_theme'),
'id' => 'background-one',
'std' => $background_defaults,
'type' => 'background' );
My Theme Options page:
My header.php:
<style type="text/css">
<?php $background = of_get_option('background-one');
echo 'body {';
if ($background['color']) {
echo '
background: ' .$background['color']. ';';
}
if ($background['image']) {
echo '
background: url('.$background['image']. ') ';
echo ''.$background['repeat']. ' ';
echo ''.$background['position']. ' ';
echo ''.$background['attachment']. ';';
}
echo '
}';
?>
</style>
Which works perfectly fine in the front-end of my site, displaying the CSS as:
body {
background: #8224e3;
background: url(images/bg03.gif) repeat top left fixed;
}
But if the user hasn't chosen a colour or image as a background through the Theme Options page, the source code will output:
body {
}
How would I be able to remove the above CSS if the user hasn't chosen a background?
From what I gather, an if statement needs to be created but I don't how to write this up correctly as I'm fairly new to php.
Secondly, how would I be able to set a default background image in the framework?
My options.php:
// Background Defaults
$background_defaults = array(
'color' => '',
'image' => '',
'repeat' => 'no-repeat',
'position' => 'top left',
'attachment' => 'fixed' );
Thanks
Just move a few things to be within an if statement, like so:
<?php
$background = of_get_option('background-one');
if ($background['color'] || $background['image']) {
echo '<style type="text/css" >';
echo 'body {';
if ($background['color']) {
echo '
background: ' .$background['color']. ';';
}
if ($background['image']) {
echo '
background: url('.$background['image']. ') ';
echo ''.$background['repeat']. ' ';
echo ''.$background['position']. ' ';
echo ''.$background['attachment']. ';';
}
echo '
}';
echo '</style>';
}
?>
And, for your second question, simply make the following change:
// Set up a default image
// NOTE: This is designed for the image to be located in your theme folder, inside an images folder
$default = get_bloginfo("template_url") . 'images/default.jpg';
// Background Defaults
$background_defaults = array(
'color' => '',
'image' => $default,
'repeat' => 'no-repeat',
'position' => 'top left',
'attachment' => 'fixed' );

Facebook PHP API - sudden problem with users_isAppUser()

we have an iframe facebookapp which worked fine till yesterday. Although we didn't change anything our app suddenly stopped working.
We could identify users_isAppUser() as a problem. The method returns that the user has not added the app though he definitely has installed the app and is logged in. We could delete the try/catch part (see code below), so that the app does not get catched in a redirect loop, but the following methods do not work either:
$this->facebook->api_client->friends_get()
$this->facebook->api_client->friends_getAppUsers()
$this->facebook->api_client->call_method('facebook.users.hasAppPermission', array('ext_perm' => 'publish_stream'))
require_login() does work and we can get the facebook userid of the logged in user.
The weird thing is, that our app worked fine for a couple of weeks till yesterday.
Have there been any secret changes to the API in the last days? Or any other conclusions what the problem could be?
I would appreciate any tips. Thanks in advance!
$this->fbuserid = $this->facebook->require_login();
// check if user has added app, exception gets thrown if the cookie has an invalid session_key i.e. user is not logged in
try {
if(!$this->facebook->api_client->users_isAppUser()) {
$this->facebook->redirect($this->facebook->get_add_url());
}
} catch (exception $ex) {
// clear cookies for application and redirect to login prompt
$this->facebook->set_user(null, null);
$this->facebook->redirect($this->configArray['appcallbackurl']);
}
<?php
// this is sample code taken from the Facebook Developers Site.Thank you to Face book
define('YOUR_APP_ID', '');
define('YOUR_APP_SECRET', '');
function get_facebook_cookie($app_id, $app_secret) {
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
$payload .= $key . '=' . $value;
}
}
if (md5($payload . $app_secret) != $args['sig']) {
return null;
}
return $args;
}
$cookie = get_facebook_cookie(YOUR_APP_ID, YOUR_APP_SECRET);
echo "<pre/>";
/*print_r($_COOKIE);
print_r($cookie);*/
$user = json_decode(file_get_contents('https://graph.facebook.com/me?access_token=' . $cookie['access_token']));
$photo = json_decode(file_get_contents('https://graph.facebook.com/100000439661780/albums?access_token=' . $cookie['access_token']));
echo "<pre/>";
print_r($photo);
?>
<img src="https://graph.facebook.com/ureshpatel5/picture" height="200" width="200" />
<html>
<body>
<?php
$albums = $facebook->api('/me/albums');
print_r($albums);
foreach($albums['data'] as $album)
{
// get all photos for album
$photos = $facebook->api("/{189346844423303_46487}/photos");
foreach($photos['data'] as $photo)
{
echo "<img src='{$photo['source']}' />", "<br />";
}
}
?>
<?php if ($cookie) { ?>
Welcome <?= $user->name ?>
<?php } else { ?>
<fb:login-button></fb:login-button>
<?php } ?>
<?php
echo $photo->source;
?>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: '<?= YOUR_APP_ID ?>', status: true,
cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
</script>
</body>
</html>

How to get Google Contacts information using Google OAuth?

I am new to OAuth, and want to create a page that gets the user's contact list from Google using the OAuth system so they don't have to login.
How do I do this? I am using php, so I would really appreciate if there is example code that does this. I can't seem to find it on Google.
Please help!
Thanks
For general OAuth principles to access Google, you might find Google's OAuth playground very useful (contacts are included there).
This is a very basic example (using the php oauth pecl extension and simplexml, it just prints out the names of the 25 first contacts):
<?php
$cons_key="your consumer key";
$cons_sec="your consumer secret";
$callback="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$req_token_url="https://www.google.com/accounts/OAuthGetRequestToken";
$auth_token_url="https://www.google.com/accounts/OAuthAuthorizeToken";
$acc_token_url="https://www.google.com/accounts/OAuthGetAccessToken";
$scope="https://www.google.com/m8/feeds/";
$scopes=urlencode($scope);
$req_scope_token_url=$req_token_url."?scope=".$scopes;
$endpoint="https://www.google.com/m8/feeds/contacts/default/full/";
session_start();
if(!isset($_GET['oauth_token']) && $_SESSION['state']==1) $_SESSION['state'] = 0;
try {
$oauth = new OAuth($cons_key,$cons_sec);
if(!isset($_GET['oauth_token']) && !$_SESSION['state']) {
$oauth = new OAuth($cons_key,$cons_sec);
$oauth->setRequestEngine(OAUTH_REQENGINE_CURL);
$request_token_info = $oauth->getRequestToken($req_scope_token_url,$callback);
if(!empty($request_token_info)) {
$_SESSION['token']=$request_token_info['oauth_token'];
$_SESSION['secret']=$request_token_info['oauth_token_secret'];
$_SESSION['state']=1;
header('Location: '.$auth_token_url.'?oauth_token='.$_SESSION['token']);
exit;
}
} else if($_SESSION['state']==1) {
$oauth->setToken($_GET['oauth_token'],$_SESSION['secret']);
$access_token_info = $oauth->getAccessToken($acc_token_url);
$_SESSION['state'] = 2;
$_SESSION['token'] = $access_token_info['oauth_token'];
$_SESSION['secret'] = $access_token_info['oauth_token_secret'];
}
$oauth->fetch($endpoint);
parseAtom($oauth->getLastResponse());
} catch(OAuthException $E) {
print_r($E);
}
function parseAtom($atomstring) {
global $oauth;
$atom=simplexml_load_string($atomstring);
foreach ($atom->entry as $entry) {
print $entry->title.", ";
}
}
?>
You can see the above code in action here.
Installing (configuring) the oauth pecl extension can be tricky, you may have to check your php.ini and/or specify a requestengine.
Hope my post helpful to all (Google contact list reader in PHP(Google OAuth))
http://anandafit.info/2011/03/08/google-contact-list-reader-in-php-google-oauth/
You need to start with Google Contacts Data API and OAuth, when you're done, this should be enough for a reference.
OK. first of all futtta i had some problems with pecl and pear stuff. so i decided to stick with ZEND. I do appreciate you posting though, your code still helped me :-)....
here is what i've got so far, taking some of the code from the ibm page posted above, but altering it to use oauth to get in.
<?php
session_start();
require_once 'common.php';
require_once 'Zend/Oauth/Consumer.php';
require_once 'Zend/Crypt/Rsa/Key/Private.php';
require_once 'Zend/Gdata.php';
require_once 'Zend/Gdata/Query.php';
$oauthOptions = array(
'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
'version' => '1.0',
'consumerKey' => 'PUT KEY HERE',
'consumerSecret' => 'PUT KEY HERE',
'signatureMethod' => 'HMAC-SHA1',
'requestTokenUrl' => 'https://www.google.com/accounts/OAuthGetRequestToken',
'userAuthorizationUrl' => 'https://www.google.com/accounts/OAuthAuthorizeToken',
'accessTokenUrl' => 'https://www.google.com/accounts/OAuthGetAccessToken'
);
?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Listing contacts</title>
<style>
body {
font-family: Verdana;
}
div.name {
color: red;
text-decoration: none;
font-weight: bolder;
}
div.entry {
display: inline;
float: left;
width: 400px;
height: 150px;
border: 2px solid;
margin: 10px;
padding: 5px;
}
td {
vertical-align: top;
}
</style>
</head>
<body>
<?
$consumer = new Zend_Oauth_Consumer($oauthOptions);
if (!isset($_SESSION['ACCESS_TOKEN_GOOGLE'])) {
if (!empty($_GET)) {
$token = $consumer->getAccessToken($_GET, unserialize($_SESSION['REQUEST_TOKEN_GOOGLE']));
$_SESSION['ACCESS_TOKEN_GOOGLE'] = serialize($token);
} else {
$token = $consumer->getRequestToken(array('scope'=>'http://www.google.com/m8/feeds'));
$_SESSION['REQUEST_TOKEN_GOOGLE'] = serialize($token);
$consumer->redirect();
exit;
}
} else {
$token = unserialize($_SESSION['ACCESS_TOKEN_GOOGLE']);
//$_SESSION['ACCESS_TOKEN_GOOGLE'] = null;
}
$http = $token->getHttpClient($oauthOptions);
$gdata = new Zend_Gdata($http);
$gdata->setMajorProtocolVersion(3);
$gdata->getHttpClient()->setRequestScheme(Zend_Oauth::REQUEST_SCHEME_QUERYSTRING);
$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/default/full?);
//$query->setMaxResults(10);
$feed = $gdata->getFeed($query);
?>
<h2><?php echo $feed->title; ?></h2>
<div>
<?php echo $feed->totalResults; ?> contact(s) found.
</div>
<?php
// parse feed and extract contact information
// into simpler objects
$results = array();
foreach($feed as $entry){
$xml = simplexml_load_string($entry->getXML());
$obj = new stdClass;
$obj->name = (string) $entry->title;
$obj->orgName = (string) $xml->organization->orgName;
$obj->orgTitle = (string) $xml->organization->orgTitle;
foreach ($xml->email as $e) {
$obj->emailAddress[] = (string) $e['address'];
}
foreach ($xml->phoneNumber as $p) {
$obj->phoneNumber[] = (string) $p;
}
foreach ($xml->website as $w) {
$obj->website[] = (string) $w['href'];
}
$results[] = $obj;
}
?>
<?php
// display results
foreach ($results as $r) {
?>
<div class="entry">
<div class="name"><?php echo (!empty($r->name)) ?
$r->name : 'Name not available'; ?></div>
<div class="data">
<table>
<tr>
<td>Organization</td>
<td><?php echo $r->orgName; ?></td>
</tr>
<tr>
<td>Email</td>
<td><?php echo #join(', ', $r->emailAddress); ?></td>
</tr>
<tr>
<td>Phone</td>
<td><?php echo #join(', ', $r->phoneNumber); ?></td>
</tr>
<tr>
<td>Web</td>
<td><?php echo #join(', ', $r->website); ?></td>
</tr>
</table>
</div>
</div>
<?php
}
?>
</body>
</html>
There are still some problems, for me it only posts 25 results and i cannot seem to get setmaxresults to work... there seems to be problems with ZEND for that... if someone knows a work around, please post.
b
Comment out the setRequestScheme method call and use max-results and you should be able to get more than 25 entries.
//$gdata->getHttpClient()->setRequestScheme(Zend_Oauth::REQUEST_SCHEME_QUERYSTRING);
$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/default/full/?max-results=999999');

Categories