Cocorico
Cocorico

Reputation: 2347

Cannot extract Facebook picture url from json graph object

I am grabbing info from Facebook's API about a certain user, using the /user_id/picture call, and I var_dump the response and see this:

var_dump($graphObject);

which gives me the response:

object(Facebook\GraphObject)#6 (1) { ["backingData":protected]=> object(stdClass)#8 (2) {   ["url"]=> string(112) "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xap1/t1.0-1/p200x200/115634790309_n.jpg" ["is_silhouette"]=> bool(false) } }

And as silly as it is, I can't figure out how to get that "url" string into a variable. I am new to this all, but I thought something would work like:

graphObject->url;

And I have tried a bunch of other things, can anyone help?

Upvotes: 1

Views: 1102

Answers (1)

Niraj Shah
Niraj Shah

Reputation: 15457

Once you get $graphObject, you can convert it into an array so you can access the objects in it, as follows:

// convert to array
$graphObject = $graphObject->asArray();

// echo URL
echo $graphObject['url'];

Upvotes: 2

Related Questions