Ricky Mossip
Ricky Mossip

Reputation: 29

How to get the picture url using the Facebook PHP SDK

I'm using the latest version of the Facebook PHP SDK (version 4). I finally figured out how to use it in my PHP code. Below is my code.

        $user_profile = (new FacebookRequest($this->session, 'GET', '/me/?fields=id,first_name,last_name,picture,timezone,gender,link'))->execute()->getGraphObject(GraphUser::className());

        $outputArray[$i]['first_name'] = $user_profile->getFirstName();
        $outputArray[$i]['last_name'] = $user_profile->getLastName();
        $outputArray[$i]['pictureURL'] = ;

What do i specify to receive the picture URL, i requested it?

Also, i manually opened up the fb php sdk file called GraphUser.php just to see if i can find the property myself. here it is on pastebin.

http://pastebin.com/K6Xg0MjN

As you can see, the GraphUser object doesn't contain any properties that deal with the picture, so where do i get the picture then?

please and thanks for reading

Upvotes: 0

Views: 1159

Answers (1)

Phillip
Phillip

Reputation: 1570

The isn't a field called picture for the user object. It's an edge:

https://developers.facebook.com/docs/graph-api/reference/v2.2/user/picture

$picture_info = (new FacebookRequest($this->session, 'GET', '/me/picture'))->execute()->getGraphObject();

$outputArray[$i]['pictureURL']=$picture_info->getProperty('url');

Upvotes: 2

Related Questions