简单的Facebook Javascript发布到流示例? [英] Simple Facebook Javascript post to stream example?

查看:67
本文介绍了简单的Facebook Javascript发布到流示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发布到用户流,没有用户提示。我无法找到可用的代码。 Facebook JSDK已经加载,我将插入代码:

I'm trying to post to user stream, without user prompt. I cannot manage to find a code that works. Facebook JSDK is already loaded and I will insert the code inside:

FB.getLoginStatus(function(response){

确保用户已经登录到我的应用程序,可以提供一个使用 publish_stream 权限?

to make sure the user is already logged to my application. Could you provide an example of publishing to the user stream using the publish_stream permission?

推荐答案

使用对话框

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

You need to use the Feed Dialog, with 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/

没有对话框

要发布没有Dialog的帖子,您需要使用 FB.api()

To make a post without the Dialog you need to use the 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/

这篇关于简单的Facebook Javascript发布到流示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆