2012-01-17 16 views
0

我需要捕捉的Oauth數據從Facebook進入我的表,我寫了這個代碼Facebook的OAuth的數據捕獲

$app_id = "340088232675552"; 
$canvas_page = "https://apps.facebook.com/appluckyprice/index.php"; 
$auth_url = "https://www.facebook.com/dialog/oauth?client_id=" 
    . $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=email,user_birthday,user_hometown"; 

我使用

$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true); 
$graph_url = 'https://graph.facebook.com/'.$data["user_id"].''; 
$user = json_decode(file_get_contents($graph_url)); 

$user_email = $data['user']->email; 
echo $user_email; 

但它不顯示任何內容,如何捕獲電子郵件?

回答

0

默認情況下,您不會從字段獲得字段,並且需要通過傳遞fields參數來顯式請求它。

$graph_url = 'https://graph.facebook.com/me?fields=email&access_token='.$data["oauth_token"]; 
+0

好的,但我如何獲得電子郵件在PHP變量? – 2012-01-17 07:35:49