在 Facebook 中,我如何在用户的墙上发布一条消息,上面写着“我在对象游戏上得分 8/10”,然后是一个 URL?
我真的不想使用完整的 API,因为我不想处理用户登录详细信息。我不介意 Facebook 是否需要进行身份验证然后发布消息。
是否可以使用新的 Graph API 和 JavaScript?
在 Facebook 中,我如何在用户的墙上发布一条消息,上面写着“我在对象游戏上得分 8/10”,然后是一个 URL?
我真的不想使用完整的 API,因为我不想处理用户登录详细信息。我不介意 Facebook 是否需要进行身份验证然后发布消息。
是否可以使用新的 Graph API 和 JavaScript?
注意 4/16/2011: stream.publish 似乎已被弃用,有一种新方法可以做到这一点:http: //developers.facebook.com/docs/reference/dialogs/feed/
您可以使用这样的东西发布到墙上,用户需要在发送之前确认。不要忘记您需要使用 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.');
}
}
);
}
在墙上发布将显示一个对话框,用于在墙上分享或不分享消息。但我想在用户的墙上静默发布消息,假设用户已经授予“发布在墙上”权限。
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);
});
考虑到你有一个代理来进行跨域调用,你可以简单地这样做......
在此示例中,YourProxyMethod 采用 jQuery.ajax 之类的哈希,在服务器端发布并在成功/错误回调中返回响应。任何常规代理都应该这样做。
诀窍是在 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);
}
});