Guy Aston
Guy Aston

Reputation: 169

Javascript SDK - An active access token must be used to query information about the current user

not the 1st time im asking for help with this, but im really stuck.

On my website when a user register he gets a personal code. I want my users to be able to share that code on their facebook wall, by only clicking a button.

My HTML CODE:

<body>

    <script>

        window.fbAsyncInit = function() {
            FB.init({
                appId      : 'My app ID', // I did replace that with my app ID***
                status     : true, // check login status
                cookie     : true, // enable cookies to allow the server to access the session
                xfbml      : true  // parse XFBML
            });

            // Additional initialization code here

        };

        // Load the JavaScript SDK Asynchronously
        (function(d){
          var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
          js = d.createElement('script'); js.id = id; js.async = true;
          js.src = "//connect.facebook.net/en_US/all.js";
          d.getElementsByTagName('head')[0].appendChild(js);
        }(document));

    </script>

The rest of my Code...

At the bottom of my HTML:

<script src="//connect.facebook.net/en_US/all.js"></script> <!--Iv'e also tried to put that inside the <head> -->
<script type="text/javascript" src="js/js.js"></script> <!--My js file-->

Post Function (Clicking the share button):

var $message = 'msg';

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

I get this error: {"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}

Upvotes: 0

Views: 1507

Answers (1)

Tobi
Tobi

Reputation: 31479

Have a look at

You're not logging people in, so you can't post to their wall accordingly. That's exactly what the error message says.

Why don't you just stick to the examples in the docs:

Furthermore, you add the JS SDK twice. The first asynchronous load is enough! You don't need to add it again manually in the HTML code.

Upvotes: 1

Related Questions