Trigger facebook action "like" with js sdk
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.
Matrym
Updated on June 30, 2022Comments
-
Matrym almost 2 years
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); } ); });
-
Matrym almost 12 yearsThanks - I could use one more bit of help though, if you would. Where is object id coming from? Are we talking about the user's fbid?
-
Matrym almost 12 yearsOr perhaps it's the object type id?
-
Terry almost 12 yearsToo long for a comment so I edited my original answer. Hope that helps.
-
Programista over 11 yearsAnd how to setup what can be liked on website, the code you provided doesn't work.