6

I have the stream_publish permission but it still pops up a dialog and there doesn't seem to be any way to pass in an autopublish bool (like it was before the graph api).

EDIT: Also tried offline_access with stream_publish.

Any ideas on how to get this to work?


function streamPublish(imageUrl, imageHref, attachName, attachHref, attachCaption) {
 FB.ui(
   {
     method: 'stream.publish',
     message: '',
     attachment: {
       name: attachName,
       caption: attachCaption,
       description: (
         ''
       ),
       href: attachHref,
       media: [
         {
           type: 'image',
           href: imageHref,
           src: imageUrl
         }
        ]
     }
   },
   function(response) {
     if (response && response.post_id) {
       //alert('Post was published.');
     } else {
       //alert('Post was not published.');
     }
   }
 );
}

1 Answer 1

7

http://www.takwing.idv.hk/tech/fb_dev/jssdk/learning_jssdk_12.html

The following will autopublish if you have the permissions unlike FB.UI :)


function publishPost(session) {
   var publish = {
     method: 'stream.publish',
     message: 'is learning how to develop Facebook apps.',
     picture : 'http://www.takwing.idv.hk/facebook/demoapp_jssdk/img/logo.gif',
     link : 'http://www.takwing.idv.hk/facebook/demoapp_jssdk/',
     name: 'This is my demo Facebook application (JS SDK)!',
     caption: 'Caption of the Post',
     description: 'It is fun to write Facebook App!',
     actions : { name : 'Start Learning', link : 'http://www.takwing.idv.hk/tech/fb_dev/index.php'}
   };

   FB.api('/me/feed', 'POST', publish, function(response) {  
       document.getElementById('confirmMsg').innerHTML = 
              'A post had just been published into the stream on your wall.';
   });
};  
4
  • 2
    You should note that pre-filling 'message' in the publish object like in the above code would break Facebook policy so don't do it in live apps.
    – Jont
    Oct 27, 2011 at 13:24
  • @Jont is correct. However, if the "message" has been supplied by the user (and they are aware that the message will be published - e.g. via checking a checkbox). Then you could use this method without breaking Facebook Policy. Dec 13, 2011 at 5:43
  • I am having problems publishing content to facebook from my app. I am not able to publish content as ato publish. Can you point me in the right direction. Apr 18, 2012 at 17:39
  • @jestro, I am going to use this solution but got error and i have done app setting is their any other setting for app please lets us know. Thanks ERROR { "error": { "message": "(#200) The user hasn't authorized the application to perform this action", "type": "OAuthException", "code": 200 } } Apr 8, 2016 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.