Bakery
Bakery

Reputation: 406

using FB.api to post to wall gives error

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 action","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!

Upvotes: 0

Views: 2084

Answers (1)

Kasper Vesth
Kasper Vesth

Reputation: 4113

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 :)

Upvotes: 2

Related Questions