0
我一直在試圖解決這個問題三天了,對於那些知道開放圖API的人來說,這非常簡單。我是新來的Facebook集成,但有一些PHP的經驗。存儲訪問令牌
基本上所有我試圖做的是從用戶檢索以下信息並將其存儲在數據庫中。
的Facebook用戶ID: 名稱 性別 電子郵件
我以做用戶ID,姓名,性別:
$contents = file_get_contents ('https://graph.facebook.com/'.$user);
$json=json_decode($contents,true);
$userid = $json['id'];
$username = $json['name'];
$usergender = $json['gender'];
$useremail = $json['email'];
這工作,我知道我需要問權限訪問我使用此代碼完成的電子郵件:
$app_id = "211665122244023";
$canvas_page = "http://apps.facebook.com/midcitymafia/";
$auth_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=email,publish_actions";
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
但是,如何獲取acces然後用它從圖表中檢索電子郵件?
## UPDATE,這是我當前的代碼,仍然不能似乎得到它的工作...require 'src/facebook.php';
$app_id = "211665122244023";
$canvas_page = "http://apps.facebook.com/midcitymafia/";
$auth_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=email,publish_actions";
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
$graph = json_decode(file_get_contents("https://graph.facebook.com/".$user_id . "/?accesstoken=" .$data['access_token']));
}
$userid = $graph->id;
$username = $graph->name;
$usergender = $graph->gender;
$useremail = $graph->email;
?>
<br>
<?php echo 'ID: ' . $userid; ?>
<br>
<?php echo 'Name: ' . $username; ?>
<br>
<?php echo 'Gender: ' . $usergender; ?>
<br>
<?php echo 'Email: ' . $useremail; ?>
謝謝,現在我不能將它存儲在我的數據庫中嗎?我的意思是,他們到期了嗎?我將如何去更新它?我已閱讀'撤銷頁面',但不真正瞭解... – 2012-01-11 13:34:21
我現在得到了這個代碼^^檢查主帖,仍然沒有工作..謝謝。 – 2012-01-11 13:46:25