繁体   English   中英

使用Facebook Graph只需使用javascript发布一条墙消息

[英]Using Facebook Graph to simply post a wall message with just 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.');
         }
       }
     );  
  }

墙上的帖子将显示一个对话框,用于在墙上共享信息。 但我想在用户的墙上静静地发布消息,假设用户已经给出了“Post on wall”权限。

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 irself中包含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);
  }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM