tags:

views:

195

answers:

1

Hi,

I am trying to get the access_token of the logged in facebook user.

I get something like this.. url followed by the code i am retrieve the code..

it says in the guide to exchange it for access_token...

https://graph.facebook.com/oauth/access_token? client_id=XXXXXXXXXXXXXX& redirect_uri=http://www.my-site.com/& client_secret=XXXXXXXXXXXXXXXXXXXXX& code=2.hJFWoMlLf3tLOSos_qNCBg_.3600.1279836000-10000100XXXXXXX|kGwPB4y5K-ijD9_1CfjSpT-oaY..

How i can exchange it for a access_token using what FB.api or jquery or javascript..

When i plug this url in the address bar.. i am able to see access_token..

I appreciate if somebody can tell me how to retrieve the access_token using javascript or jquery.

Thanks.

A: 

If you are using the JavaScript SDK, then after logging in the user, getting the access token in your JavaScript code is as simple as:

FB.getSession().access_token

However, getSession may return null if a user is logged out, so the proper way is to first check for null before accessing the token.

var session = FB.getSession();
if(session != null) { // user is still logged in
    console.log(session.access_token);
}
Anurag

related questions