我想解码用户的位置。认为
"id": "100000564553314",
"name": "Adi Mathur",
"location": {
"id": "106487939387579",
"name": "Gurgaon, Haryana"
}
我正在使用脚本来获取名称,但位置给了我一个错误
不能将 stdClass 类型的对象用作数组
$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 $_SESSION['name']=$user->name; // WORKS
echo $_SESSION['fbid']=$user->id; // WORKS
echo $_SESSION['location']=$user->location[0]; // ERROR
echo $_SESSION['location']=$user->location->name; // ERROR