00:00
00:00
Newgrounds Background Image Theme

BACKRUMS just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Php Json & Facebook

1,834 Views | 4 Replies
New Topic Respond to this Topic

Php Json & Facebook 2013-02-25 14:39:53


I have been searching all day and trying many different methods. I cant seem to get this code to display any information whatsoever.

<?php
$graph = json_decode(file_get_contents("https://graph.facebook.com/122243664545681/photos"));

$picture = $graph->picture;
$pageid = $graph->id;
echo  $picture.' '.$pageid;
?>

yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea

Response to Php Json & Facebook 2013-02-25 14:53:32


The Facebook JSON is stored inside a "data" index, which is an array, so you will need to access the 0-th element of the "data" array (or, in this case, the data object, since you aren't using the JSON as an array) to get the data you want:

<?php
$graph = json_decode(file_get_contents("https://graph.facebook.com/122243664545681/photos"));

$picture = $graph->data[0]->picture;
$pageid = $graph->data[0]->id;
echo  $picture.' '.$pageid;
?>

If you perform a var_dump on the "data" object it becomes a little more obvious how you should be accessing the JSON data:

<?php
$graph = json_decode(file_get_contents("https://graph.facebook.com/122243664545681/photos"));
var_dump($graph->data);
?>

Response to Php Json & Facebook 2013-02-25 14:56:10


And citricsquid brings up a good point; I didn't think to mention that you can use a loop to dump out all the information, rather than just the first element.

Response to Php Json & Facebook 2013-02-25 15:03:13


Ok ill try these out thanks a lot guys!


yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea yea