最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Trigger facebook action "like" with js sdk - Stack Overflow

programmeradmin2浏览0评论

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 : '.html' });

According to:


Edit - This is what I ended up using:

                $("#testLink").click(function(){
                    $.post("/<?php echo $user_profile[id]; ?>/og.likes", 
                        {
                            access_token: FB.getAuthResponse()['accessToken'], 
                            object: ".php" 
                        },
                        function(data) {
                            alert("Data Loaded: " + data);
                        }
                    );
                });

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./pumpkinpie.html' });

According to: https://developers.facebook./docs/opengraph/actions/#create


Edit - This is what I ended up using:

                $("#testLink").click(function(){
                    $.post("https://graph.facebook./<?php echo $user_profile[id]; ?>/og.likes", 
                        {
                            access_token: FB.getAuthResponse()['accessToken'], 
                            object: "http://www.matrym./fb/temp.php" 
                        },
                        function(data) {
                            alert("Data Loaded: " + data);
                        }
                    );
                });
Share Improve this question edited Jun 27, 2012 at 19:59 Matrym asked Jun 27, 2012 at 1:31 MatrymMatrym 17.1k35 gold badges99 silver badges141 bronze badges 1
  • So what is the URL that was shared? Can you set the image and text that goes with the like? – Drew Baker Commented Sep 1, 2012 at 6:43
Add a ment  | 

1 Answer 1

Reset to default 5

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./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.

发布评论

评论列表(0)

  1. 暂无评论