0

在下面的代码中。

$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']

我怎么解决这个问题?

4

1 回答 1

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          
        }
    } 
}
于 2013-05-29T14:41:55.550 回答