In my database some users have Facebook IDs stored, as once they logged into my website via Facebook. For each of those users I would like to store a profile picture, which would be retrieved from their Facebook accounts.
Facebook PHP SDK specifies the following way to get a user picture:
/* PHP SDK v4.0.0 */
/* make the API call */
$request = new FacebookRequest(
$session,
'GET',
'/me/picture'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
The problem is the $session
param. Currently, I get the FacebookSession object after the user logs into my website via Facebook. However, for what I want to achieve, I don't have the session present.
Is it possible in PHP SDK to get Facebook user profile picture when having only the user ID, and without them being logged into Facebook?
I hope this helps,
http://graph.facebook.com/USERNAME OR USERID/picture?type=large
http://graph.facebook.com/USERNAME OR USERID/picture?type=small http://graph.facebook.com/USERNAME OR USERID/picture?type=square
You do not need to log into facebook just use USERNAME OR USERID. This is simple, basic thing and require only Googling... If you're not looking for this, please elaborate the task you're doing...
Good Luck!!!
Simply use the following Graph path via GET request:
/{user_id}?fields=picture.type(large),id,name
Field type can be one of the following values:
Or using width and/or height value like this:
/{user_id}?fields=picture.width(200).height(200),id,name
Also you can add redirect=0 param. By default the picture edge will return a picture instead of a JSON response. If you want the picture edge to return JSON that describes the image set redirect=0 when you make the request.
So you will have the following JSON response:
{
"picture": {
"data": {
"height": 120,
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/hprofile-xaf1/v/t1.0-1/c53.10.120.120/165675_138088076251005_752993_n.jpg?oh=a9450bf53f2d2294531e11ae28be99c1&oe=56C740A5",
"width": 120
}
},
"id": "138087416251071",
"name": "Zenonis",
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.