2 Replies - 791 Views - Last Post: 08 January 2013 - 02:54 PM Rate Topic: -----

#1 gregwhitworth  Icon User is offline

  • Tired.
  • member icon

Reputation: 219
  • View blog
  • Posts: 1,604
  • Joined: 20-January 09

Facebook Graph API do one call, not multiple

Posted 07 January 2013 - 02:30 PM

Hey guys,

I'm using the graph api to get a users album id and count, then from there get the photos in that album. The total photo count will be 14. The way I am currently doing it, it uses file_get_contents() on the actual API which is then done multiple times. I would prefer to do one FQL type query while maintaining support for the new graph API.

So that you guys can see what I'm doing here are the two functions I'm referring to:

function get_facebook_albums() {
		$url = 'http://graph.facebook.com/' . $this->fb_id . '/albums';
		$result = file_get_contents( $url );
		$result = json_decode($result);
		$i = 0;
		while( $i <= 14 ) {
			foreach( $result->data as $info ) {
				$this->fb_albums[$info->name] = array('id'=>$info->id, 'count'=>$info->count);
				$i + $info->count;
			}
		}
	}

function build_facebook_photos_array() {
		$images = array();
		$i = 0;
		foreach( $this->fb_albums as $key=>$album ) {
			$photos = $this->get_facebook_photos( $album );		
			foreach( $photos->data as $photo ) {
				while($i <= 14) {
					$url = sprintf('http://graph.facebook.com/%s', $photo->id);
					$result = file_get_contents( $url );
					$image_set = json_decode($result);			
					$images[$i]['small'] = $image_set->picture;
					$images[$i]['large'] = $image_set->source;
					$i++;
				}
			} // album data
		} // foreach album	

		return $images;



Any help would be greatly appreciated as I would love to do just one call with array like so:

[albumid]=> 
     array('photo_id' => 
          array('large'=> source, 
                'small'=> picture)
     )



Is This A Good Question/Topic? 0
  • +

Replies To: Facebook Graph API do one call, not multiple

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10595
  • View blog
  • Posts: 39,237
  • Joined: 27-December 08

Re: Facebook Graph API do one call, not multiple

Posted 07 January 2013 - 06:33 PM

Looking at the Album documentation, it has a Photos connection, shown here. It looks like it allows you to pull multiple photos at once. Hope this helps some!
Was This Post Helpful? 0
  • +
  • -

#3 gregwhitworth  Icon User is offline

  • Tired.
  • member icon

Reputation: 219
  • View blog
  • Posts: 1,604
  • Joined: 20-January 09

Re: Facebook Graph API do one call, not multiple

Posted 08 January 2013 - 02:54 PM

True, and I'm not sure why I added in the additional API call, but still I'm having to do the following:

Get album id to then call photos.

I would like to have one query that calls all photos in all albums and just return the latest, say 14.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1