views:

49

answers:

2

Hello,

I can't get the proper token to reach the extended user information (specifically email) from the Facebook API. I've correctly given my app permission to retrieve the email, so I know I have the correct permissions. I'm trying to convert a session to a token using the exchange_session method as you can see below in my code:

        $url = 'https://graph.facebook.com/oauth/exchange_sessions';

        $curl_handle=curl_init();
        curl_setopt($curl_handle,CURLOPT_URL,$url);
        curl_setopt($curl_handle, CURLOPT_POSTFIELDS,'type=client_cred&client_id=' . FB_APPID . '&client_secret=' . FB_SECRET . '&sessions=' . $session->session_key);
        curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
        curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
        $buffer = curl_exec($curl_handle);
        curl_close($curl_handle);

        $tokendata = json_decode($buffer);
        $user = json_decode(file_get_contents('https://graph.facebook.com/me/?wrap_access_token=' . $tokendata[0]->access_token));
print_r($user);    

If I use the '/me' it always errors out with "An active access token must be used to query information about the current user."

If I swap out '/me' with the current user ID, it will give me the basic user info, but not the extended info.

The token that I get back is indeed the full token with session info in this format:

123456789012345|6.abcdefghijklmnopqrstuv__.1234.1234567890-1234567890|abcdefghijklmnopqrstuvwxyza.

Help?

Thanks! Andy

A: 

Use official facebook's php sdk to avoid the headache with tokens handling

zerkms
I am using the standard FB SDK.
andypants
A: 

Should it be /me/?access_token= instead of /me/?wrap_access_token=?

serg
THANK YOU THANK YOU THANK YOU! That sure as heck was it. The Facebook API documentation is very, very unclear as I didn't see it posted like that anywhere. I appreciate it!!!
andypants
@andypants you are welcome :)
serg

related questions