I have this code:
FB.api('/me',
{fields: 'id, first_name, last_name, email, link, gender, picture'},
function(response) {
Pass data to php file which saves it in the database
}
The picture field contains an url to a 50x50 image. How can I get an url to a larger picture?
I have been looking at the documentation here:
https://developers.facebook.com/docs/graph-api/reference/user/picture/
but I am still confused.
Maybe this can help
$facebook->api(me?fields=picture.width(800).height(800))
Related
If i have facebook users photo's URL, for example: https://fbcdn-sphotos-e-a.akamaihd.net/hphotos-ak-ash3/885089_523687507674066_732194510_o.png
Can i retrieve user's name or id which own this photo?
First, fetch the photo_id from the url. For eg:
Link: https://fbcdn-sphotos-e-a.akamaihd.net/hphotos-ak-ash3/885089_523687507674066_732194510_o.png
PhotoId: 523687507674066
Then make the \GET request to this ID. Just like this:
\GET http://graph.facebook.com/523687507674066
(you can validate this link in the browser)
You'll get the JSON response just like-
....
from: {
category: "Recreation/sports website",
name: "Emocje do pełna",
id: "290868840955935"
},
....
So, you just have to fetch the id from the from paramter
Yep https://www.facebook.com/photo.php?fbid=523687507674066 The middle number is the photo id
Late response on this - sorry.
Taking the middle number from the image file name, you can sometimes find the profile it came from.
www.facebookcreep.com has a tool for this. It takes the number and looks up to see if it can locate the profile. I believe the pictures needs to have been shared to public is the downfall though.
i am using facebook registration plugin. I can get the profile pic of the user by knowing either his facebook username or userid (accesstoken not required for pic). I can get userid or username by getting the access token etc. But , i cant get the username or userid from accesstoken here. So, is there any way i can get the username or userid or large profile pic from registration plugin?
Thanks
I couldn't get the accepted answer to work for me but this did:
You can get specific sizes of the profile pic as well.
FB.api("/me/picture?width=180&height=180", function(response) {
console.log(response.data.url);
});
See the Facebook documentation to see what different picture sizes you can get.
And a complete demo with login at: Get Facebook Profile Picture with Javascript SDK
Using the Javascript SDK, you can use Javascript to get the profile picture by doing this:
FB.api("/me", {fields: "id,name,picture"}, function(response){
FB.api(
{
method: 'fql.query',
query: 'SELECT src_big FROM photo WHERE aid IN ( SELECT aid FROM album WHERE owner="' + response.id + '" AND name = "Profile Pictures")'
},
function(data) {
alert( data[0].src_big ); // this will alert the URL of the profile picture (stored in data[0].src_big), replace the alert with some useful operation
}
);
});
See similar post: Facebook Javascript SDK - Query Profile Picture
Hope this helps.
I'm using oauth to log facebook users in to my app. I'm testing with my FB account and with the basic permissions scope. Facebook docs say that I should be able to get 'picture' with basic permissions, but my account has no 'picture' property when I access it with the API. First name, last name, etc. are there though.
Is this because my account is not publicly viewable? Why might this happen? I definitely have a profile picture attached.
Here's my fb link: http://www.facebook.com/josh.nankin
best way is to keep the basic permissions and fire the request for the image in a separate step. Ask the graph api in this way:
https://graph.facebook.com/[fb_user_id]?fields=picture.type(small)
larger image:
https://graph.facebook.com/[fb_user_id]?fields=picture.type(large)
You will get a JSON response like:
{
"id": "100001XXXXXXXXX",
"picture": {
"data": {
"url": "http://profile.ak.fbcdn.net/hprofile-XXXX/41524_1000018XXX51507_XXXX3_q.jpg",
"is_silhouette": false
}
}
}
You can derive the profile photo URL directly from the basic standard OAuth info returned from facebook as Josh Nankin noted, BUT with a clarification.
You can still use the user's ID returned to request the photo, for example:
https://graph.facebook.com/914431778578699/picture?type=large
is the same as
https://graph.facebook.com/dark.eye.1/picture?type=large
This way only one request must be made, because you can interpolate the photo URL as you store it in the DB.
So, still not sure why the graph api does not return a picture property when you hit the /me path on the API, but once you have the username from /me, you can get the picture pretty easily at:
https://graph.facebook.com/USERNAME/picture
https://developers.facebook.com/docs/reference/api/user/:
“picture: The URL of the user's profile pic (only returned if you explicitly specify a 'fields=picture' param)”
You haven’t probably overlooked the part marked in bold …?
Actually you don't need to allow public access to get the profile picture since you can get the USER_ID. Though the USER_ID you can navigate to the profile picture easily.
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
console.log('Welcome! Fetching your information.... ');
var url = '/me?fields=id,name';
FB.api(url, function(response) {
var linkpp = 'https://graph.facebook.com/' + response.id + '/picture?type=large';
document.getElementById("id_of_link_tag").href = linkpp;
});
});
}
You can change the type in variable linkpp to type=small which returns a low resolution image.
var linkpp = 'https://graph.facebook.com/' + response.id + '/picture?type=small';
Suppose that we put like button on the link "http://myshop.com/product/1"
We want to check if a user click liked on this link "http://myshop.com/product/1" or not.
If user cliked like on this. we will gave some discount for him or give him some reward.
how to do this
As long as it is an Open Graph URL you can check the url_like table
SELECT user_id FROM url_like WHERE user_id = me() and url="THE_URL_TO_CHECK"
A successful JSON response would contain the user_id so you should just place a conditional function to return true or false after executing the query.
You can use the Javascript SDK from facebook. You can read all likes from an user or ask for specific page:
FB.api("/me/likes/" + OBJECT_ID, function(response) {
// Do some staff here with page data
})
FB.api("/me/likes/", function(response) {
// Do some staff here with all pages data
})
You can use the Graph API explorer in order to test this.
If your case, you need to know your Object ID in the Facebook Open Graph. You can check this in the following site
I use Graph API and I need to get users' profiles pictures by their UIDs.
It's easy to do: http://graph.facebook.com/[Facebook UID]/picture
I remember, some time ago, there was a litte Facebook Logo (litter 'f'-char) on these profile pictures. But now, I get only profile pictures without this logo.
How can I get images with this 'f'-logo?
Facebook doesn't store images with the 'f' on, so it's a little hacky to get at them.
I've found that this works:
You'll need the final image url, after graph.facebook.com/[id]/picture redirects.
http://external.ak.fbcdn.net/safe_image.php?&url=[imageurl]&logo
eg. me
I think it's not possible using the graph api.
It was possible using FQL (dont know if it is still working):
SELECT pic_with_logo FROM user WHERE uid = "..."
or use xfbml with <fb:profile-pic facebook-logo="true">
With jQuery and JS API you can make an FQL call:
FB.api({ method: 'fql.query', query: 'SELECT uid, pic_with_logo FROM user WHERE uid = me()' }, function(response) {
var user = response[0];
$('#container').append('<img src="'+user.pic_with_logo+'"/><br>');
});
also you can try:
pic_small_with_logo, pic_big_with_logo, pic_square_with_logo and the pic_with_logo i use in example.
here is the user table:
https://developers.facebook.com/docs/reference/fql/user/
Based on Tom's answer, Here is php example to get user's
$_json = json_decode(file_get_contents('http://graph.facebook.com/[FACEBOOK_UID]?fields=picture'));
if (isset($_json->picture)) {
header("Location: http://external.ak.fbcdn.net/safe_image.php?&url=" . $_json->picture . "&logo");
exit;
}
Here is what we do:
Query picture url via opengraph
Get the picture url from json object
redirect the page to facebook image handler with addition &logo to url