javascript 用js sdk触发facebook动作“喜欢”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11218218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Trigger facebook action "like" with js sdk
提问by Matrym
What is the correct syntax for triggering a "like" action via FB's js sdk? A custom action looks like this:
通过 FB 的 js sdk 触发“喜欢”动作的正确语法是什么?自定义操作如下所示:
FB.api('/me/recipebox:cook', 'post',
{ recipe : 'http://www.example.com/pumpkinpie.html' });
According to: https://developers.facebook.com/docs/opengraph/actions/#create
根据: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);
}
);
});
回答by Terry
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
只要满足以下条件,应用程序就可以代表用户发布内置的 Like 操作:
- 应用内内容的查看者是经过 Facebook 认证并授予应用发布操作权限的 Facebook 用户
- 应用内内容有一个开放图表对象页面,该页面使用开放图表元标签正确标记
- 观看者有意点击了与应用内内容相关联的应用内“喜欢按钮”
you call the API like so:
您可以像这样调用 API:
FB.api('/{object id}/likes', 'post');
Reference: https://developers.facebook.com/docs/opengraph/actions/builtin/likes/
参考: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.
“喜欢”必须由网站管理员预先配置,否则 Facebook 不知道您真正“喜欢”什么。每个赞都有一个与之关联的对象 ID。如果它是您自己的网站,您必须设置您网站上的哪些内容可以被点赞(并且 FB 将一个 ID 与其关联),然后您可以代表用户为该对象提交点赞。