2

I am creating my first app in facebook. In that i am trying to access the user's page account details. I used this code:

FB.getLoginStatus(function(response) {
          if (response.status === 'connected') {
            alert('connected');
            var uid = response.authResponse.userID;
            var accessToken = response.authResponse.accessToken;
            getusername();              

}

Here i can able to get the user's main account id ,access_token, name everything. For getting the user's page account details i used this code

function getusername(){
    FB.api('/me/accounts', function(response){
            var p_accessToken = response.accessToken;
            var p_name = response.name;
            alert('The pagename is:'+ p_name + 'Page access token is' + p_accessToken);

        });

But it alerted the name and access_token as undefined. I dont know how to access the name, access_token of the page.

I think I need to change this p_accessToken =response.accessToken line.

But i dont know how to get this. Can anyone help me .

9
  • Have you asked for Page permission? Commented Mar 8, 2013 at 6:59
  • No. How i can get the permission. I think I have to get permission using manage pages. But i dont know how to use that. Can u help me @Anvesh Saxena Commented Mar 8, 2013 at 7:04
  • 1
    FB.login(function(){//Call back function to do things like checking if user logged in or not},"scope":"manage_pages") Commented Mar 8, 2013 at 7:10
  • FB.login(function(response) { if (response.authResponse) { testAPI(); } else { // cancelled } }, "scope":"manage_pages"); i gave like this it is giving syntax error Commented Mar 8, 2013 at 7:52
  • Sorry, error on my part. Instead of "scope":"manage_pages" please write {"scope":"manage_pages"} also check FB.login Commented Mar 8, 2013 at 8:01

1 Answer 1

2

There was an issue with your code, I have corrected it

<script> 
FB.login(function(response){ 
FB.api('/me/accounts', function(response){ 
   var p_accessToken = response.data[0].access_token; 
   var p_name = response.data[0].name; 
   alert('The pagename is:'
           + p_name + 'Page access token is' 
           + p_accessToken);});}
   ,{scope:"manage_pages"}); 
</script>

the data is an array with your accounts being on different index numbers also its access_token instead of accessToken

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.