after user authenticates FB app, how can you get all likes from a specific domain? - facebook

I have a website called example.com with several internal pages that are liked.
I created a FB app.
when a user authenticates the FB app, I want to fetch ALL user likes such as: example.com/page1, example.com/page2, etc.
(a single user can have up to 100+ likes on the internal pages of example.com) I essentially want to get all the liked URL's (and associated FB graph ID) the authenticated user has made on my example.com website.
is there a way to do this?
perhaps via a facebook.api call? or perhaps a FQL query? I am open to PHP or JS.
please help! thanks.
...fyi, My initial thought is to for each user, fetch ALL their likes, parse through each one to make sure it came from example.com, and then store those like URL's into a local database. when the user re-visits the site, I will query my database for likes associated with that user. this did not seem the most efficient as it would require storing all likes ever made on my website. any help would be much appreciated.

If you just want to store when a user likes a page on your website why not make use of the edge.create and edge.remove events the Facebook JS SDK provides? Example:
FB.Event.subscribe('edge.create', function(targetUrl, elm) {
// Make a request to server to save 'Like' information
});
FB.Event.subscribe('edge.remove', function(targetUrl, elm) {
// Make a request to server to remove 'Like' information
});

I see in the attributes of the like plugin, that the ref attribute might be what you could use to determine where a like came from. Of course your href attribute would need to be the same on all locations of the like button.
Or, you can register your site with facebook insights and track it there. See https://www.facebook.com/insights/

The User API reference is here: https://developers.facebook.com/docs/reference/api/user/
Here's how you get all the likes via the JS API (unless they're more than one page, they you get a subset of the likes):
FB.api('/me/likes', function(response) {
console.log(response);
});
You need to be logged in, and you need the user_likes permission.

Related

How to send multiple link to facebook debugger

I have a website with some dynamic urls (for example a page who show event details thanks to event id in get variable), but during the share with facebook, at the first attempt the thumbnail image doesn't appear due the page isn't already fetched by facebook.
Then I must go to the debugger https://developers.facebook.com/tools/debug/og/object/ and submit every pages to get a valid thumbnail to the users.
There's a script or a way to send multiple links to this debugger, or there's another way to achieve the indexing of new pages by facebook?
You can refresh the Open Graph tags with a POST request to the Graph API, i think it´s not in the Facebook docs (at least i could not find it) - but it definitely works:
$.post('https://graph.facebook.com', {
id: 'http://www.yourdomain.com/somefile.html',
scrape: true
}, function(response) {
console.log(response);
});
Just an example with jQuery, of course you can just use CURL on the server too.

How to get the facebook user id that likes my website (not a facebook site)

I am making a raffle within the people that had make an "I like" to a certain article of my external website (non facebook). In order to choose the winner I need to know who has made the I like.
This query:
https://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url='myWEBSITE'&format=json
Only get me the total count of I Likes but not the users ID
This query is perfect:
https://api.facebook.com/method/fql.query?query=SELECT%20user_id%20FROM%20like%20WHERE%20object_id%3D%MY_object_ID&access_token=MY_ACCESS_TOKEN
But how do I get an OBJECTID for an external url??
Thanks in advance
Object can be any thing like video, note, link, photo, or album but can not be any FB page or Url.. So I guess its not possible to get the user Id for a URL.
If you are using JS SDK / Like plugin in your website to like it, i think you can subscribe to an event and then use some ajax calls to get those userIds whenever they instantly like it.
See Somnath Muluk's answer in https://stackoverflow.com/a/13467793/269521

How do I generate Facebook like button with only the FB page ID

So I have a database table with the Facebook page ID's of my users. I would like to generate a like button dynamically with only the ID available to me to do this. The problem as I see it is that I don't know what the data-href attribute is supposed to have considering that Facebook page url's look like this: http://facebook.com/pages/hyphenated-name/<?=$FB_id?> and I don't have the hyphenated name stored in my database to generate the that url.
Is there another URL structure Facebook's back-end will accept that just has the ID and not the hyphenated name, but will still count likes on that person's Facebook fan page? Is this impossible?
You can do a look up of the id, and retrieve the link of the page stored.
example: https://developers.facebook.com/tools/explorer?method=GET&path=191825050853209
refer to: https://developers.facebook.com/docs/reference/api/page/ under link connection.
This method will require use of the graph api, or one of the sdks.
refer to: https://developers.facebook.com/docs/reference/api

How to auto like facebook page from other site?

On the facebook page,we can click the like button to like the page.
How can we use any api or plugin to realize from other site?
You can not automatically like an object for a user nor can you present like via the APIs. This prevents anyone "secretly" having users like pages / objects.
The solution is to embed a like button to your page and give users a clear reason to use it [sell the benefit of liking your page]. You can run a separate version for individual pages, objects or just an aggregate button for all of your site via the data-href element.
http://developers.facebook.com/docs/reference/plugins/like/
You can check if a user has liked your page using:
FB.api('/me/likes', function(response) {
console.log(response);
});
Loop through the response and look for your page ID.
The open-graph api has now been updated to support creating (and deleting) likes.
See here:
https://developers.facebook.com/docs/opengraph/actions/builtin/likes/

'Like' a page using Facebook Graph API

Using the Graph API I'd like to be able to have an authorized user "like" a page.
I tried posting the following
https://graph.facebook.com/${PAGE_ID}/likes?access_token=${ACCESS_TOKEN}
And I get an HTTP error 500 accompanied by "Invalid post_id parameter" in the JSON response body. Looks like the /likes resource is suited to liking a wall post and not a page. How do I get this to work with a page?
Facebook has announced support for liking URL's outside of Facebook by using the official built-in Like action. You need to have publish_actions permissions. The graph url for this is:
https://graph.facebook.com/[User FB ID]/og.likes?object=OG_OBJECT_URL&access_token=USER_ACCESS_TOKEN
However, you cannot use this to like a page on Facebook currently, as the documentation states:
For Facebook Pages or websites that do not integrate with Facebook
Authentication, developers should continue to use the Like button
social plugin.
Update June 2016
It's still not possible to like a page using Facebook API, as stated in the /{user_id}/likes documentation page about Creating/Updating/Deleting:
You can't perform this operation on this endpoint.
In previous versions the message was clearer (see the quote below), but the result is the same: it's not possible.
May 2014
The /{user-id}/likes documentation page States about Publishing Likes of Facebook Pages:
You can't publish using this edge, as it is not possible to like a Facebook Page via any API. You should use the Like Button if you want people to be able to like a page in your app.
This is the most obvious and clear statement that has been able to give me an answer to the question.
if your app is an open graph app, now you can like using the api, and no need for the button anymore.
https://developers.facebook.com/docs/opengraph/actions/builtin/likes/
If you want this functionality in a page tab or canvas page within facebook (say to allow for liking the page from within a likegated page), a work around you can involves what Tom Wells suggested in his reply to Luke. You first embed the iframe version of their like button on your page, and then simply listen for the edge.create event in your JS like so:
FB.Event.subscribe('edge.create',
function(response) {
alert('You liked the URL: ' + response);
// ...
}
);
In the callback, you can deal with with what happens when the user has liked the page, say like navigating away from the like-gate page, or showing liked-only content.
When the user clicks the iFrame like button, your JS code should receive the edge.create event assuming the iFrame was configured to point to the url of the page in question.
I believe this is not allowed except for specific partner sites, like yelp. The reason is security, you would be able to put some javascript on a page and have everyone that visits that page "Like"ing it without their knowledge.
See How do I "Like" a URL? on the Facebook Platform Developer Forum
You can like an object with its object id using Facebook api using the following piece of code
[FBRequestConnection startForPostWithGraphPath:[NSString stringWithFormat:#"/%#/likes",{object_id}] graphObject:nil completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
//do you customisation post like here
}];