在以下代码中。
$data = $facebook->api( '/'.$fbuid.'/likes', 'GET', array( 'access_token' => $access_token ));<br />
$data1 = $facebook->api( '/'.$fbuid.'/groups', 'GET', array( 'access_token' => $access_token ) );
$user_data = array_merge($data['data'], $data1['data']);
echo json_encode($data1['data']);
$data1['data']
显示一个空数组(有时)。
$user_data
仅包含仅$data['data']
我该如何解决这个问题?
答案 0 :(得分:0)
获取此类数据的简便方法:
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $appId . "&redirect_uri=" . $redirectUri //change with your data
. "&client_secret=" . $appSecret . "&code=" . $code;
$response = @file_get_contents($token_url);
if($response) {
$params = null;
parse_str($response, $params);
if(isset($params['access_token']) && $params['access_token']) {
$graph_url = "https://graph.facebook.com/me?access_token="
. $params['access_token'];
$user = json_decode(file_get_contents($graph_url));
if(isset($user)){ // you can do some isset verification
var_dump($user); //you can check all data with this
print $user->name; // this prints guy's name
}
}
}