Reputation: 17053
What is the correct syntax for triggering a "like" action via FB's js sdk? A custom action looks like this:
FB.api('/me/recipebox:cook', 'post',
{ recipe : 'http://www.example.com/pumpkinpie.html' });
According to: https://developers.facebook.com/docs/opengraph/actions/#create
Edit - This is what I ended up using:
$("#testLink").click(function(){
$.post("https://graph.facebook.com/<?php echo $user_profile[id]; ?>/og.likes",
{
access_token: FB.getAuthResponse()['accessToken'],
object: "http://www.matrym.com/fb/temp.php"
},
function(data) {
alert("Data Loaded: " + data);
}
);
});
Upvotes: 4
Views: 11486
Reputation: 14219
Once you satisfy the following conditions...
An app can publish a built-in Like action, on behalf of the user, as long as the following conditions are true:
- The viewer of the in-app content is a Facebook user who has Facebook-authed and granted the app publish_actions permission
- The in-app content has an Open Graph object page that is properly marked-up using Open Graph metatags
- The viewer has intentionally clicked on an in-app “like button” associated with the in-app content
you call the API like so:
FB.api('/{object id}/likes', 'post');
Reference: https://developers.facebook.com/docs/opengraph/actions/builtin/likes/
"Likes" have to be pre-configured by webmasters, otherwise Facebook has no idea what you're actually "liking". Each like has an object id associated with it. If it's your own website, you have to set up what on your site can be liked (and FB associates an ID with it), then you can submit a like on the user's behalf for that object.
Upvotes: 5