-2

我正在尝试在没有用户提示的情况下发布到用户流。我无法找到有效的代码。Facebook JSDK 已经加载,我将在其中插入代码:

FB.getLoginStatus(function(response){

确保用户已经登录到我的应用程序。您能否提供一个使用publish_stream权限发布到用户流的示例?

4

1 回答 1

2

带对话框

您需要使用 Feed 对话框,其中FB.ui()

function postToFeed() {
    // calling the API ...
    var obj = {
        method: 'feed',
        link: 'https://developers.facebook.com/docs/reference/dialogs/',
        picture: 'http://fbrell.com/f8.jpg',
        name: 'Facebook Dialogs',
        caption: 'Reference Documentation',
        description: 'Using Dialogs to interact with users.'
    };

    function callback(response) {
        document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
    }

    FB.ui(obj, callback);
}

文档:https ://developers.facebook.com/docs/reference/dialogs/feed/

没有对话

要在没有对话框的情况下发布帖子,您需要使用FB.api()

var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('Post ID: ' + response.id);
  }
});

文档:https ://developers.facebook.com/docs/reference/javascript/FB.api/

直接网址

https://www.facebook.com/dialog/feed?
  app_id=APP_ID&
  link=https://YOUR_DOMAIN&
  picture=http://YOUR_DOMAIN/image.jpg&
  name=Facebook%20Dialogs&
  caption=API%20Dialogs&
  description=Using%20Dialogs%20to%20interact%20with%20users.&
  redirect_uri=http://YOUR_DOMAIN/response

文档:https ://developers.facebook.com/docs/reference/dialogs/feed/

于 2012-07-02T05:47:44.483 回答