1

I'm unable to get the page access token for some reason I only recieve the page id... this is my code:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js" type="text/javascript"></script>

</head>
<body>
<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId      : 'APP-ID',
            status     : true, 
            cookie     : true,
            xfbml      : true,
            oauth      : true,
        });
    };
    (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>
<div class="fb-login-button" data-scope="email,user_checkins,manage_pages">Login with Facebook</div>

<div class="result">Start</div>
<div class="result_app_installed">Start</div>
<script>
// Get access token
$.get('https://graph.facebook.com/102561956524622?fields=access_token', function(data) {
  alert(data);
});

// Get data if user is application is installed on that page or not.
$.get("https://graph.facebook.com/102561956524622/tabs/255792581098802",
   function(data) {
     alert(data);
   });
</script>
</body>
</html>

What I am trying to do is to get the page access token and then check if application in installed on that page.. What am I doing wrong?

3 Answers 3

2

Try something like:

FB.api('/me/accounts',function(response) {alert(response);})

The Page token is returned in data as access_token

You will need manage_pages permission.

Sign up to request clarification or add additional context in comments.

Comments

0

https://graph.facebook.com/102561956524622?fields=access_token
won't work. In order to get an access_token for any fan page You need to do the steps explained here:

writing on the wall on behalf of my fanpage

Instead of using $.get it's better to use Facebook JavaScript SDK:

https://developers.facebook.com/docs/reference/javascript/

so for the second request it would be:

FB.api('/102561956524622/tabs/255792581098802',
function(response) {

  alert(response);

});

Bear in mind that in order to make this FB.api call You need to authorize the app first

3 Comments

still not working ... i'm getting different error: "Error validating application." "OAuthException" this is my code: pastebin.com/YPdeU0tM
I think You're mistaking code and accessToken, You cannot use code as an accessToken, please refer to this documentation: developers.facebook.com/docs/authentication
also to get an access_token using Javascript You can use developers.facebook.com/docs/reference/javascript/… the method if connected returns among others an access_token, if You debug it You'll see exactly what it returns
0

Actuelly its very easy

FB.api('/'+[PAGE_ID]+'?fields=id,likes,name,access_token', function(response) {
    console.log(response.access_token);
}); 

Dont forget to check if user is logged in.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.