开发者

using FB.api to post to wall gives error

开发者 https://www.devze.com 2023-04-12 23:26 出处:网络
I am trying to post a message to the users wall using a application and FB.api. This is my page: <html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:fb=\"https://www.facebook.com/2008/fbml\">

I am trying to post a message to the users wall using a application and FB.api. This is my page:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="https://www.facebook.com/2008/fbml">
  <head>
    <title>My Feed Dialog Page</title>
  </head>
  <body>
<div id='fb-root'></div>
<script src='http://connect.facebook.net/en_US/all.js'></script>
 <script> 




  FB.init(
    {
      appId: "MY_ID",
      status: true,
      cookie: true,
      oauth : true
    }
  );


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

    } 
    else 
    {
        alert('User is logged out');
    }
}, {publish_stream : true});

</script>
  </body>
</html>

This fails. Using chromes javascript debug i find the following:

/**/ FB.ApiServer._callbacks.f1abfdaec({"error":{"message":"(#200) The user hasn't authorized the application to perform this ac开发者_如何学JAVAtion","type":"OAuthException"}});

As you can see, I provide the publish_stream request to the login function. Is there anything else i need to provide? I cant find this in the docs.

Is there anything else that I am doing wrong here?

Thanks!


You are defining the permissions wrong. To make it work you need to change

}, {publish_stream : true});

into

}, {scope: 'publish_stream'});

Then it should work :)

0

精彩评论

暂无评论...
验证码 换一张
取 消