【问题标题】:FB.api post to wall : access token?FB.api 贴到墙上:访问令牌?
【发布时间】:2012-04-20 20:32:11
【问题描述】:

我正在尝试使用 javascript sdk 发布到已连接用户的 facebook 墙上,这是我的代码:

     var connecter=false;
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'xxxxxxx', // App ID
      oauth      : true,
      channelUrl : '//www.streamazing.net/js/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    FB.Event.subscribe('auth.login', function (response) {
               window.location.reload();
            });

    FB.Event.subscribe('auth.logout', function (response) {
               window.location.reload();
            });



    FB.getLoginStatus(function(response) {
            if (response.status === 'connected') {
                connecter=true;
                FB.api('/me', function(user) {
                var user2=user;
                console.log(user2.name);

                });

            }
        else connecter=false;
        });





    var body = 'This is a test';
                FB.api('/me/feed', 'post', { message: body }, function(response) {
                    if (!response || response.error) {
                        console.log(response.error);
                    } else {
                        alert('Post ID: ' + response.id);
                    }
                });
};

这是控制台日志:

code: 2500
message: "An active access token must be used to query information about the current user."
type: "OAuthException"

我用这段代码请求许可:

<fb:login-button autologoutlink='true'  scope='email,user_birthday,status_update,publish_stream'></fb:login-button>

我不明白为什么 facebook 向我询问访问令牌,有人可以帮助我吗? 非常感谢。

【问题讨论】:

  • 你能告诉我你是怎么解决这个问题的吗?我也遇到同样的问题????

标签: javascript facebook sdk token


【解决方案1】:

如果您想使用 Javascript SDK 发布到用户的供稿,请改用 FB.ui。 http://developers.facebook.com/docs/reference/javascript/FB.ui/

否则,publish_stream 扩展权限所需的访问令牌存储在 response.authResponse.accessToken 下的 FB.getLoginStatus 方法中。 http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

【讨论】:

    【解决方案2】:

    您需要使用 access_token= 向所有 FB URL 发出请求。

    【讨论】:

      【解决方案3】:

      调用 FB.init();在声明了所有 fb sdk 函数之后。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-10-05
        • 2012-04-26
        • 1970-01-01
        • 2011-06-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多