I m开始在Facebook提出申请,Im在获得一些用户信息方面遇到问题。
我获得的信息如下:
hometown_location
current_location
work
我的守则是:
<?php
$app_id = "";
$app_secret = "";
$my_url = "";
session_start();
$code = $_REQUEST["code"];
if(empty($code)) {
$_SESSION[ state ] = md5(uniqid(rand(), TRUE)); //CSRF protection
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&scope=email,offline_access,publish_stream,user_birthday,user_education_history,user_location,user_hometown,user_relationships,user_relationship_details,user_work_history&state="
. $_SESSION[ state ];
echo("<script> top.location.href= " . $dialog_url . " </script>");
}
if($_REQUEST[ state ] == $_SESSION[ state ]) {
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret . "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$graph_url = "https://graph.facebook.com/me?access_token="
. $params[ access_token ];
$user = json_decode(file_get_contents($graph_url));
echo("Hello " . $user->name. <br /> );
echo("id " . $user->id. <br /> );
echo("mail " . $user->email. <br /> );
echo("birthday " . $user->birthday. <br /> );
echo("sex " . $user->sex. <br /> );
echo("hometown_location " . $user->hometown_location. <br /> );
echo("relationship_status " . $user->relationship_status. <br /> );
echo("current_location " . $user->current_location. <br /> );
echo("education " . $user->education. <br /> );
echo("work " . $user->work. <br /> );
}
else {
}
?>
我与“性别”交织在一起,但我可以 figure出其他人。