我是 Facebook API 的初学者。我刚刚创建了一个应用程序,我想显示朋友的姓名和数量:
这是我的代码:
<?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>";
?>
我懂了
致命错误:未捕获的 OAuthException:验证应用程序时出错。由于系统错误,无法获取应用程序信息。在第 1238 行的 D:\softs\UwAmp\www\facebook-php-sdk\src\base_facebook.php 中抛出
我试图只显示这样的用户名:
<?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