我想用此显示性别,但它不起作用:
foreach($results as $val) {
$url = 'https://graph.facebook.com/'.$val->id.'/?fields=gender';
$data = json_decode($url,1);
echo $val->id.' : '.$data->gender;
}
目标输出:
(id : gender)
12345 : male
12346 : female
etc.
答案 0 :(得分:1)
data
。 应该是(两者都可以):$data->gender;
$data->data->gender;
$data['data']['gender'];
foreach($results as $val) {
$url = 'https://graph.facebook.com/'.$val->id.'/?fields=gender';
$request = file_get_contents($request_url);
$json = json_decode($request);
echo $val->id.' : '.$json->data->gender;
}