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
Related
I want to check if a user liked my fan-page from my website and if he did i skip the step and if he didnt i want to suggest him to like my fan-page,its all on my website i dont want to put a landing page or something else on my fan-page.all of it is on my website,i don't want to put a landing page or anything else on my fan-page.
Thanks
there are only 2 ways for this:
-) use the edge.create event: https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/
downside: this can only check right after clicking a like button on your website. so, if the user comes back, you canĀ“t be sure if the like button is still clicked. also, you never get the id of the user, of course
(deprecated)
-) authorization with facebook login > you can check for the user likes > user_likes permission needed. but i doubt that you really want to authorize the user just for this...
the graph api call you could use:
me/likes?target_id=[page-id]
subscription:
permission user_subscriptions needed. graph api call would be the following:
me/subscribedto?user=[user-id]
You need user_likes permission to view like information about the current session user.
refer to: http://developers.facebook.com/docs/reference/login/user-friend-permissions/
then simply use fql to request information.
SELECT page_id FROM page_fan WHERE uid=me() AND page_id=22934684677
If user likes the page graph will return id of page.
Example graph request like for page Facebook.
http://developers.facebook.com/tools/explorer/135669679827333/?fql=SELECT%20page_id%20FROM%20page_fan%20WHERE%20uid%3Dme()%20AND%20page_id%3D20531316728
{
"data": [
{
"page_id": 20531316728
}
]
}
Else array will be empty.
{
"data": [
]
}
I am using the latest Facebook C# SDK (v5.0.40 at time of writing) from here: http://facebooksdk.codeplex.com/.
I have created a test iFrame app in Facebook and got the CSASPNETFacebookApp sample running so that it displays the name of the currently logged in user within Facebook.
What I would now like to do is display different content in my iFrame depending on whether the user has "liked" the page. However the signed_request never seems to contain that information. From what I can see in the FacebookSignedRequest.cs I will only get the payload which contains the page information if the algorithm is AES-256-CBC HMAC-SHA256 but I only ever get HMAC-SHA256 returned.
What am I doing wrong? How do I get it to return the page information? Is it a problem with the setup of my app in Facebook or a configuration issue with the .NET app?
Thanks in advance.
var fb = new FacebookClient("access_token");
dynamic parameters = new ExpandoObject();
parameters.method = "pages.isFan";
parameters.page_id = "{you page id}";
dynamic result = fb.Get(parameters);
bool isFan = result == true;
Neil Knight's answer is technically correct, you can use FQL to look up whether a user has liked a page and it did help to set me on the right path. However my issue was actually more one of set up rather than code. What I didn't understand is that you only receive the "like" information in the signed request if your app is running within the "context of a page". If you set it up correctly then Facebook will pass your app the like flag without the user needing to "Allow" your app.
The steps are:
(1) Create your iframe application in Facebook
(2) Set up a tab url for your app in the app settings. This is what the parent page will use when it generates a link in the left hand column to go to your app.
(3) Go to your "App profile page", the URL will be something like this: http://www.facebook.com/apps/application.php?id=12345 Where 12345 is your app ID.
In the left hand column below the logo image there should be a link "Add to Page". If you click on that link you will be presented with a list of pages that you are the admin for. Select the page you want to like in your app.
Now if you navigate to your page you should get a link to your app in the left hand column. It is only when clicking on that link that you will get the page id and like status passed through to your application.
Hope this helps someone having the same issue.
You could use FQL in order to achieve this. I have just done this using the following statement:
var the_query = FB.Data.query("SELECT uid FROM page_fan WHERE page_id = {0} and uid={1}", page_id, user_id);
In order for this to work, I had to ask the user to "Allow" my application so that I had permission to check to see if they liked the page. Then, it was a simple case of checking the result and displaying the necessary <div>:
the_query.wait(function (rows) {
if (rows.length == 1 && rows[0].uid == user_id) {
$("#myLikeContent").show();
} else {
$("#myNoLikeContent").show();
}
});
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
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/
Using Facebook's Graph API, given a username xyz (assuming they've authenticated my site), how do I get a list of all of the facebook pages that the user administers?
The accounts property on the user object says:
The Facebook pages owned by the current user. If the manage_pages permission has been granted, this connection also yields access_tokens that can be used to query the Graph API on behalf of the page.
http://developers.facebook.com/docs/reference/api/user
After getting access token you can get all details of list of all of the facebook pages that the user administers.
https://graph.facebook.com/[FACEBOOKUSERID]?metadata=1&access_token=
The output will look like
{
"name": "Facebook Developer Garage Austin - SXSW Edition",
"metadata": {
"connections": {
"feed": "http://graph.facebook.com/331218348435/feed",
"picture": "https://graph.facebook.com/331218348435/picture",
"invited": "https://graph.facebook.com/331218348435/invited",
"attending": "https://graph.facebook.com/331218348435/attending",
"maybe": "https://graph.facebook.com/331218348435/maybe",
"noreply": "https://graph.facebook.com/331218348435/noreply",
"declined": "https://graph.facebook.com/331218348435/declined"
}
}
}
Use an fql query! That is the best way to get the pages for which the user is admin. You will also be able to restrict the names also. i.e pages with empty names A sample fql query which gives you the page details as well.
SELECT page_id,page_url,name,pic_square FROM page WHERE page_id IN (SELECT page_id FROM page_admin WHERE uid = " + **UserId** + ") and name!=''
UserId -- Id of the admin
NOTE
This method will not work from version 2.1 of graph api as fql was deprecated from that version onwards
I found the answer, you need to use FQL, passing in the appropriate access_token:
https://api.facebook.com/method/fql.query?query=SELECT%20page_id%20FROM%20page_admin%20WHERE%20uid=XXXX&access_token=YYYY
Here's what I use. It works perfect
$pages = $facebook->api(array('method' => 'fql.query','query' => 'SELECT page_id FROM page_admin WHERE uid = '.$uid.''));
foreach($pages as $k=>$v) {
echo 'page id#:'.$v['page_id'].'<br/>';
}
This is of course after you have the session created for the fb user! The $uid would be the profile id# of the specific facebook user your returning of a list of managed pages for.
#rmorrison - This is not graph API though. With the new "like" addition, you can use this URL: h ttps://graph.facebook.com/me/likes?access_token=blah! or h ttps://graph.facebook.com/USER_ID/likes?access_token=blah!
Fql is the best way to get the pages of the user for which he is the admin. As the others like likes of user will give all the pages that the user like.
You can get list of pages from a simple Facebook Graph API Hit.
https://graph.facebook.com/{user-id}/accounts?access_token={access-token}
It will give a list of pages for user which he/she has created.
access_token is valid for an hour or less. What should someone do in order to get the details even after. I was trying to result get the result from
https://graph.facebook.com/v2.3/search?q=coffee&type=place¢er=37.76,-122.427&distance=1000&access_token=xyz
This worked for an hour or so but how do i get the result after an hour...without going for a login.