How to auto like facebook page from other site? - facebook

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/

Related

Like an Open Graph action

I have created an application with their associated Open Graph actions, already approved by Facebook.
When a user publishes an activity/action in their feed, it's possible to "like" it from there. But is it possible to like it from another page, ie. with the "Like" plugin? by somebody who is not an user of the application?
Thanks
To like an action you need to have the user access_token or use the FB api for that
as described here: https://developers.facebook.com/docs/opengraph/actions/#like_action
This is how we do it:
FB.api("[action id]/likes", "post", function(response){...});
The like button works with a url, which is how facebook indexes pages.
Graph objects have urls which define them, and so you can of course put the url of a graph object as the url for a like button.
The graph actions don't have a url and so I don't think that you can attach a like button to an action.
I'm pretty sure that there's no way to like an action outside of facebook.

Like button for Facebook page shows generic Facebook description in News Feed

I want a Like button on my web site that Likes my Facebook profile (rather than my web page), so that when a user clicks it they subscribe to my Facebook posts.
I've created the Like button using the tool at https://developers.facebook.com/docs/reference/plugins/like/
Further down that page there is an FAQ entry:
Can I link the Like button to my Facebook page?
Yes. Simply specify the URL of your Facebook page in the href
parameter of the button.
So, I've edited the href parameter to point to my Facebook page. eg:
https://www.facebook.com/myfacebookid
When a user clicks the Like button it has the desired effect. The user ends up having Liked my Facebook page. This is easily verified by the user going to my Facebook profile and checking that the Like button has changed to Liked.
But. When the user clicks the Like button, and entry appears in their News Feed with a generic Facebook description. ie:
Facebook is a social utility that connects people with friends and
others who work, study and live around them. People use Facebook to
keep up with friends, upload an unlimited number of photos, post links
and videos, and learn more about the people they meet.
I don't want a generic post about Facebook to appear. I want the description to relate to my Facebook account and/or web site.
Normally, I could modify this behavior with the Opengraph og: description tag, but as the page in the href is a Facebook page and not my own, I can't control the Opengraph tags.
I'm pretty sure that this was working okay before I enabled timeline for my account, so maybe this is a timeline bug?
So, how do I add a Like button which a) Likes my Facebook profile rather than one of my own web pages, and b) Posts a description of my Facebook profile rather than give a generic Facbook description?
Are all your fields in the info part of your page filled in, and/or completed? I just tested your theory and it seemed to work as expected, only thing is I know all fields in "info" are filled it. Give that a try.
This may happen if you have filled invalid/incomplete/wrong og tags in past and later changed them. Facebook's cache creates problem sometime.
Try putting all the entries (i.e. all og tags) and then debug them here http://developers.facebook.com/tools/debug. This debugger gives a detailed info about the url with og tags and also clears the cache for you.
This should solve the problem.
You have 3 important fields that used on page opengraph: Name,Description,Profile Image.
They are used when some one post your link on Facebook, or Google or some else web service that handle opengraph.
Actually, the suggested answers currently do not work and there is an open bug / ticket on Facebook for it. Up to now, there's no fix.
The problem is that you can not use simply https://www.facebook.com/myfacebookid. You should copy and paste the exact page URL. If you have a low number of likes it would look something like https://www.facebook.com/pages/[YourPageName]/[Your page Id]/, and this is the URL that you should use at this point.
If it does not work, try also https://www.facebook.com/[YourPageName]/[Your page Id]/.
In short, copy-paste the URL, do not type it manually.

Like an object on Facebook outside Facebook

I've been trying to use the Like button generator to get a Like button for some content on my fan page: http://www.facebook.com/photo.php?fbid=363385833679921&set=a.314588171893021.85085.305618229456682&type=1
What I want to do is show the likes this photo got on Facebook in the like button on my site and vice versa.
This seems to work for the actual fan page url but doesn't work for individual photos (haven't tested other objects).
You are able to see the likes the object on Facebook got through the graph API call: http://graph.facebook.com/363385833679921. So shouldn't that be available on non-Facebook sites as well?
Anyone know a solution to this without having to make a custom handler to show and post likes on site?
Why don't you just use the API to read the comments and likes on the object? Any user's access token will work if that user can see the object

How to get insights for separate "Like" button(s), not for whole domain

I have put a like button on my web page which is dynamically linked to different Facebook fan pages. I have checked the insights pages of Facebook but it gives an overall count of button clicks from my site. Is there a way to get more detailed information like how many users clicked which Like button?
Facebook documentation mentions a ref tag that can be added to Like button code, however this tag does not show up in insights reports. Also I know I have the chance use JavaScript events to handle reporting personally, but I cannot since I am using iframe version of the button.
Also, is there a way for the Facebook fan page admin (the one that my like button links to) to see that detail exactly? e.g. "xx number of clicks generated with like button from this site (or app--which the like button is tied ?)"
In my opinion, Facebook insights are far from being complete.
If I where you, I would track like events, and visits from like using an analytic tools like Google Analytics. This is what I do for my website, and the website of the company I am working for.
However, Facebook insights can give you complementary metrics (age, gender...).
Regards
Antoine
As Antoine says, you can track your likes with Google Analytics. I don't know about insights though.
Here's more info on how to track likes with GA:
http://www.socialmediaexaminer.com/how-to-track-tweets-facebook-likes-and-more-with-google-analytics/
Use FB.Event.subscribe:
FB.Event.subscribe('edge.create',
function(response) {
alert('You liked the URL: ' + response);
}
);
Why use iframe if it is limiting you from doing what you need to do? Use XFBML or HTML5 versions and use the event handler to do an AJAX call to your server. Kinda like, Dr it hurts when I hit my thumb with a hammer, and the Dr says don't hit your thumb.

'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
}];