Check state of a Facebook like button in web page [duplicate] - facebook

This question already has answers here:
facebook like button - do you know if web user likes your page [duplicate]
(2 answers)
How to check if a user likes my Facebook Page or URL using Facebook's API
(5 answers)
Closed 10 years ago.
I want to check the status of Facebook like button on my web page. I want to this completely on client side without querying anything (if possible)
One idea is to check the style of the page. I have seen that there is an element with class "... like_button_like" or "...like_button_no_like" depending of the status. Is there a way to query this?
As I said, I don't want to delve into querying Facebook for this with FQL or anything else.

No. This is not possible without connecting user with your application. You doesn't need any additional permissions for that.
You cannot check for DOM elements class attribute since it resist in iframe which is served from facebook.com and cross-domain policy does't allow you to do this.

enter code hereIf we want to check user does like facebook page, we may use Javascript like this:
FB.api({ method: 'pages.isFan', page_id: 'YOUR-PAGE-ID' }, function(resp) {
if (resp) {
alert('You like the Application.');
} else {
alert('You don't like the Application.');
}
});
But if we want to know if use does like our website (not facebook page) we may use our own database to store user id when user click like, or click unlike.

Related

how to check if you liked fan page with php without app access token [duplicate]

This question already has answers here:
How to check if a user likes my Facebook Page or URL using Facebook's API
(5 answers)
Closed 9 years ago.
How to check if you liked fan page with php without app access token? I need to check if you liked fan page to know if that i will hide iframe of page like, to not display it all times while users open my site.
Is it possible? I need to check it with php with get content or curl.
<iframe id="closebox3" src="http://www.facebook.com/plugins/like.php?href=https://www.facebook.com/rohelhayatt&layout=button_count&show_faces=false&width=60&action=like&colorscheme=light&height=31" scrolling="no" frameborder="0" ></iframe>
You cant. You can either implement an idempotent "like" button which will always send a like request(and another button to unlike) or use javascript sdk to get the iframe on your site.
Use the Graph API to find what data you can access.
Replace 'me' with the post you would like to 'like' and go from there.
https://developers.facebook.com/tools/explorer?method=GET&path=me
Update
You can only like posts, pictures and such. Not pages and other stuff in the top level of th graph. You need Javascript sdk or log into facebook.
Sorry for the confusion, hope this helps!

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/

Storing FB likes in database

I'm working on picture contest site which have to allow user to vote with facebook like button. At the end of a round, a have to check all picture likes and store it in our database. Well, what's proper way of doing this? How can I use links.getStats function for getting that data and storing it in the database?
Similar question is found here:
How can I store the number of facebook Likes of a particular url in my own database?
but it isn't answearing my question because I have to get exact number of likes/votes in short period in time.
I'm using ASP.NET MVC but any other solution should be fine.
Use a js callback to record the like button clicks (probably via an ajax call back to your db).
FB.Event.subscribe('edge.create', function(response) {
// do something with response.session
});
See https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/ for more details.

How to know if the user already like the page in Facebook Likebox?

I need to find a way to know if the reader already liked my page. Is there a method in Facebook API to know this?
The like button handles this for you. It automatically toggles the state of the button depending on whether the user has already liked the page.
If you need this outside the use of the like button, then if your page is not of the type news article, then you should be able to look up whether the user has liked it by using a combination of the graph api and an FQL query to pull out the object id as defined in the documentation
Also, if you're working with an app in an iFrame, Facebook already passes in the signed_request ( https://developers.facebook.com/docs/authentication/signed_request/ ) a 'page' parameter which among other things lets you know if the current user already likes your page

Check if user is a fan of some Facebook page, or has put it in his favorites [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
In facebook connect, how can I check if a user is a fan of my facebook page? Is it possible to track?
How can I check thought the FB Javascript API if the current user is a fan of some page (not my own app or page, but another specific page)?
I need to check this from within the page inserted into the FB's canvas IFRAME, throught the JS SDK...I need to check whether he has "subscribed" to that page, is a fan of it (clicked "I like it") and possibly if he has put it into his favorites.
Is this possible?
This works for me in the JS API:
FB.api({ method: 'pages.isFan', page_id : fbPageId }, function(response){
if(response == true){
alert('the user is a fan');
}else{
alert('the user is not an fan or we don't have permission to check')
}
});
Cheers,
Jeremy