你如何使用FB.UI自动发布?

jes*_*tro 6 javascript facebook facebook-graph-api

我有stream_publish权限,但它仍然会弹出一个对话框,似乎没有任何方法可以传递autopublish bool(就像它在图形api之前).

编辑:还尝试使用stream_publish offline_access.

有关如何使其工作的任何想法?


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

jes*_*tro 7

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

如果您拥有与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.';
   });
};  
Run Code Online (Sandbox Code Playgroud)

  • 您应该注意,在上述代码中预填充发布对象中的"消息"会破坏Facebook策略,因此请勿在实时应用程序中执行此操作. (2认同)