使用 Facebook Graph 只需使用 javascript 即可发布留言墙

发布于 2024-08-30 16:25:16 字数 176 浏览 2 评论 0原文

在 Facebook 中,我如何在用户墙上发布一条消息,说“我在物体游戏上得了 8/10”,然后发布一个 URL?

我真的不想使用完整的 API,因为我不想处理用户登录详细信息。我不介意 Facebook 是否需要进行身份验证然后发布消息。

是否可以使用新的 Graph API 和 JavaScript?

In Facebook how can I post a message onto a user's wall saying "I scored 8/10 on objects game" then a 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.

Is it possible using the new Graph API and JavaScript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

開玄 2024-09-06 16:25:16

注意 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.');
         }
       }
     );  
  }

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/

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.

 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.');
         }
       }
     );  
  }
朱染 2024-09-06 16:25:16

在墙上发布将显示一个对话框,用于选择是否在墙上分享消息。但我想将消息默默地发布在用户的墙上,假设用户已经授予“在墙上发布”权限。

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);
 });

Post on wall will 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);
 });
就是爱搞怪 2024-09-06 16:25:16

考虑到您有一个代理来进行跨域调用,您可以简单地执行此操作...

在此示例中,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);
  }
});

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.

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.

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);
  }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文