How can I check if a facebook like button has been clicked?
I've put faceb开发者_开发百科ook like buttons into my wordpress blog... the idea is to use them as kind of a voting mechanism for posts. What I would like to do is automatically add a comment for the blog post everytime someone 'likes' it via the facebook like button.
So my question is- does the like button api provide some kind of a callback to my page if someone 'successfully' likes something? - ie. they have not already liked it before, and they get through the process of submitting it to facebook successfully.
Thanks for any help. Fyi I am very new to the facebook api
-rich
You need to subscribe to edge.create
event according to docs:
FB.Event.subscribe('edge.create', function(href, widget) {
alert('You just liked '+href);
});
but for some reason I couldn't make it work last time I tried...
I use this to get track of the liked of users. In this case every time one user press the like button it mades a post (its send some hidden id )to another php file and save it to my database. i use this for something like you whant to do.
NOTE: i use jquery to build the ajax post.
-------------------------------------------
window.fbAsyncInit = function() {
FB.init({appId: 'xxxxxxxxxxxxxxxxxx', status: true, cookie: true,
xfbml: true});
B.Event.subscribe('edge.create', function(href, widget) {
$(document).ready(function() {
var h_fbl=href.split("/");
var fbl_id=h_fbl[4];
$.post("http://mypage.com/like.php",{ idfb:fbl_id,rand:Math.random() } )
}) });
};
You can check it using the folowing facebook-api call:
JavaScript (untested):
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.');
}
});
PHP (well tested):
$facebook = new Facebook(array(
'appId' => 'YOUR-APP-ID',
'secret' => 'YOUR-APP-SECRET-KEY',
));
$facebook->api(array(
'method' => 'pages.isFan',
'page_id' => 'YOUR-PAGE-KEY'
))
Source: http://forum.developers.facebook.net/viewtopic.php?id=101406
For further informations see the Facebook Developer Manual. http://developers.facebook.com/docs/reference/rest/pages.isFan/
Please remember that the REST-API (used in this examples) will be deprecated soon.
If you don't know where to get the SDKs you can take a look at this page: http://developers.facebook.com/docs/sdks/
精彩评论