2013-05-29 108 views
0

在下面的代碼中。
facebook php sdk響應錯誤

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

陣列conrtains數據我該如何解決這個問題呢?

回答

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   
     } 
    } 
} 
+0

感謝您的建議,它的工作,但what't在我的代碼的問題! –

+0

抱歉,不知道:) –