Using Facebook Graph to simply post a wall message with just javascript

前端 未结 3 968
无人及你
无人及你 2020-12-04 06:43

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

相关标签:
3条回答
  • 2020-12-04 07:25

    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);
     });
    
    0 讨论(0)
  • 2020-12-04 07:29

    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);
      }
    });
    
    0 讨论(0)
  • 2020-12-04 07:44

    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.');
             }
           }
         );  
      }
    
    0 讨论(0)
提交回复
热议问题