使用 Facebook Graph 只需使用 javascript 即可发布墙消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2724977/
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
Using Facebook Graph to simply post a wall message with just javascript
提问by Glycerine
In Facebook how can I post a message onto a user's wall saying "I scored 8/10 on objects game" then a URL?
在 Facebook 中,如何将一条消息发布到用户的墙上,说“我在对象游戏上得分 8/10”然后是 URL?
I really don't want to have to use the full API, as I don't want to handle user login details. I don't mind if Facebook needs to authenticate and then post the message.
我真的不想使用完整的 API,因为我不想处理用户登录详细信息。我不介意 Facebook 是否需要进行身份验证然后发布消息。
Is it possible using the new Graph API and JavaScript?
是否可以使用新的 Graph API 和 JavaScript?
回答by Soufiane Hassou
Note 4/16/2011:stream.publish seems to have been deprecated, There's a new way to do this: http://developers.facebook.com/docs/reference/dialogs/feed/
注意 4/16/2011:stream.publish 似乎已被弃用,有一种新方法可以做到这一点:http: //developers.facebook.com/docs/reference/dialogs/feed/
You can use something like this to publish to a wall, the user will need to confirm before it get sent. Don't forget that you'll need to use FB.init and include the JS SDK link.
你可以使用这样的东西来发布到墙上,用户需要在发送之前确认。不要忘记您需要使用 FB.init 并包含 JS SDK 链接。
function fb_publish() {
FB.ui(
{
method: 'stream.publish',
message: 'Message here.',
attachment: {
name: 'Name here',
caption: 'Caption here.',
description: (
'description here'
),
href: 'url here'
},
action_links: [
{ text: 'Code', href: 'action url here' }
],
user_prompt_message: 'Personal message here'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
}
回答by Nehal
Post on wallwill show a dialog box to share the message on wall or not. But I wanted to post the message silently on user's wall, assuming that user had already given "Post on wall" permission.
贴在墙上将显示一个对话框来共享或不共享墙上的消息。但是我想在用户的墙上默默发布消息,假设用户已经授予“在墙上发布”权限。
FB.api('/me/feed', 'post', {
message:'my_message',
link:YOUR_SITE_URL,
picture:picture_url
name: 'Post name',
description: 'description'
},function(data) {
console.log(data);
});
回答by Mayank Jain
Considering that you have a proxy to make cross domain calls, you can simply do this...
考虑到你有一个代理来进行跨域调用,你可以简单地这样做......
In this example, YourProxyMethod takes a jQuery.ajax like hash, makes a server side post & returns the response in success/error callbacks. Any regular proxy should do.
在这个例子中,YourProxyMethod 接受一个 jQuery.ajax 像散列,使服务器端发布并在成功/错误回调中返回响应。任何常规代理都应该这样做。
The trick is to include app_id and access_token in the URL irself. Also, your FB app should have sufficient permissions to make this call.
诀窍是在 URL 自身中包含 app_id 和 access_token。此外,您的 FB 应用程序应该具有足够的权限来进行此调用。
YourProxyMethod({
url : "https://graph.facebook.com/ID/feed?app_id=APP_ID&access_token=ACCESS_TOKEN",
method : "post",
params : {
message : "message",
name : "name",
caption : "caption",
description : "desc"
},
success : function(response) {
console.log(response);
},
error : function(response) {
console.log("Error!");
console.log(response);
}
});

