开发者

Having Trouble Accessing Email from Facebook Oauth

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开发者_如何学Go 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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜