2012-09-04 146 views
0

我是Facebook API的初學者。我剛剛創建的應用程序,我想顯示的姓名和朋友的號碼:Facebook API錯誤致命錯誤:(未捕獲OAuthException:錯誤驗證應用程序)

這是我的代碼:

<?php 

require_once 'facebook-php-sdk/src/facebook.php'; 

$appapikey = '133XXXX60164049'; 
$appsecret = ' ce6a47dfd838WWWWWW34f387b28633660'; 

$facebook = new Facebook($appapikey, $appsecret); 

$user_id = $facebook->getUser(); 

$friends = $facebook->api('/me/friends'); 

echo "<p>Hello <fb:name uid=\"$user_id\" useyou=\"false\" linked=\"false\" firstnameonly=\"true\"></fb:name>, you have ".count($friends)." friends"; 

foreach($friends as $friend){ 
    $infos.=$friend.","; 
} 

$infos = substr($infos,0,strlen($infos)-1); 

$gender=$facebook->api_client->users_getInfo($infos,'sex'); 

$gender_array = array(); 

foreach($gender as $gendervalue){ 
    $gender_array[$gendervalue[sex]]++; 
} 

$male = round($gender_array[male]*100/($gender_array[male]+$gender_array[female]),2); 
$female = 100-$male; 

echo "<ul><li>Males: $male%</li><li>Females: $female%</li></ul>"; 

?> 

我得到這個

Fatal error: Uncaught OAuthException: Error validating application. Cannot get application info due to a system error. thrown in D:\softs\UwAmp\www\facebook-php-sdk\src\base_facebook.php on line 1238


我想只顯示用戶名如下:

<?php 

require_once 'facebook-php-sdk/src/facebook.php'; 

$appapikey = '453976ergerger647366'; 
$appsecret = 'fexxxxxxxxeb39bbce717b8062'; 

$facebook = new Facebook($appapikey, $appsecret); 

$user_id = $facebook->getUser(); 



echo "<p>Hello <fb:name uid=\"$user_id\" useyou=\"false\" linked=\"false\" firstnameonly=\"true\"></fb:name>"; 
?> 

但它不起作用。只有「你好」出現:s

回答

0

我認爲你的問題在foreach($friends as $friend)部分。

如果我是正確的,它會返回一個數組{data}。所以你需要說

foreach(friends['data'] as $friend) 

也許做一些評論,看到這裏的錯誤是,讓一個print_r($friends)看到陣列的模樣!

+0

有一些意見,我可以說錯誤發生在這一行: $ friends = $ facebook-> api('/ me/friends'); – Slrg

+0

我試圖添加這個: $ friends = $ facebook-> api_client-> friends_get();但仍然是相同的問題 – Slrg

+0

刪除它,並檢查是否可以顯示$ user_id –

相關問題