Using Facebook Graph to simply post a wall message

2019-01-12 16:46发布

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?

3条回答
太酷不给撩
2楼-- · 2019-01-12 17:36

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);
 });
查看更多
男人必须洒脱
3楼-- · 2019-01-12 17:40

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.');
         }
       }
     );  
  }
查看更多
我只想做你的唯一
4楼-- · 2019-01-12 17:46

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);
  }
});
查看更多
登录 后发表回答