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
Related
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';
I'm trying to get the user photos, but I cannot get the user's photos data.
I'm trying this:
$photos = $facebook->api('https://graph.facebook.com/'.$profileFID.'/photos?access_token='.$access_token);
print_r($photos);
I'm sure the URL is correct since pasting it in the browser shows the photos array. However when I try to print the array to check if I got it I get only this:
( [id] => https://graph.facebook.com/1409006586/photos )
How can I get the full array with the user photos?
The Facebook SDK will take care of constructing the url for you (and append the access_token), you just need to build the query:
$photos = $facebook->api('me/photos');
If the user is not currently logged in but you have the access_token, then use:
$photos = $facebook->api($profileFID.'/photos', 'get', array('access_token'=>$access_token));
P.S: always put your queries in a try...catch blocks
https://graph.facebook.com/1409006586/photos
replace photo by picture
ex
https://graph.facebook.com/4/picture
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'm trying to tag a user (having its userid), with a Graph request made to a picture just uploaded to a Page Gallery.
Permissions I use in the app are:
#"read_stream", #"offline_access", #"publish_stream", #"manage_pages",#"photo_upload",#"user_photos" and with a access_token to the session got from page_it?fields=access_token item (that works for picture upload in gallery).
And I use them to upload the photo to a Gallery on a Fan Page successfully.
When I try to tag the user with a graph request in the form:
POST to picture_id/tags with param: "to"->userid
I get only facebookErrDomain error 10000 as if permissions are not right.
From API Documentation seems that only user_photos and publish_stream are required and no mention to page-galleries photo is made.
I'm quite clueless about this issue.
It's possible. You need to collect the page's specific token by placing a call to /me/accounts. And then tag the photo using page's access token. Once you get that, you can tag the photo using it's Graph Object Id and user id whom you are tagging.
if (accessToken) {
var data = {
"access_token": accessToken,
to:userId,
x:x,
y:y
}
FB.api("/" + photoId+"/tags/"+userId , 'post', data, function(response) {
//here is the response
});
}
Hope it helps. The key is the access token that is specific to that page :)
Is there a way to retrieve the list of Facebook users that have clicked the like button on an external website?
E.g. there is a domain example.com which has been confirmed via Facebook Insights to belong to fbUser1 (using OG meta tags).
Somewhere on example.com there is a page with multiple XFBL like buttons, each one pointing to a further specific URL on example.com, e.g. example.com/xyz, example.com/abc etc.
What I'd like to get is the list of users that liked example.com/xyz and of those who liked example.com/abc.
My intuitive approach would be to look at graph.facebook.com/123456789/likes (where the number is the ID of the domain taken from FB insights), but this always returns an empty dataset:
{
"data": [
]
}
I've also tried getting an OAuth access token from https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=APPID&client_secret=APPSECRET (where APPID and APPSECRET are taken from a FB application that is marked as owning the domain using OG meta tags), but that makes no difference.
I'd also be interested in a non-OpenGraph (i.e. JS SDK, FQL etc.) solution.
EDIT: Using the following code (according to WideBlade's answer below) still gives me an empty list of likes (the second query never returns):
var objectsQuery = "select id from object_url where url in ('http://example.com/xyz', 'http://example.com/abc', 'http://example.com/123')";
var likesQuery = "select object_id from like where object_id = {0}";
FB.Data.query(objectsQuery).wait(function (objectRows) {
console.log(objectRows);
FB.Array.forEach(objectRows, function (objectRow) {
FB.Data.query(likesQuery, objectRow.object_id).wait(function (likeRows) {
console.log(likeRows);
})
});
});
FQL Should do the trick.
$facebook->api_client->fql_query('SELECT user_id FROM like WHERE object_id="OBJECTID"');
Here is the link.
Some general info about FQL.
FQL is initiated using the JavaScript SDK, in this way.
If you can post some sample code-I can try and give some more specific help.
A note should be made-once you've got the user ID's, you can just query the names and get them in a list.
EDIT: To get the URL of an object you should query this table using fql.
This cannot be done. Facebook does not allow you to query for specific user ID's of people who have liked a certain page. This is because of privacy concerns.
See the disclaimer on this page https://developers.facebook.com/docs/reference/fql/like/