我需要使用此应用程序打印朋友要去的事件。 {user-id} / events不起作用,很可能是因为访问令牌不允许它!我的好友列表已经打印出来,我只需要提取他们要去的事件。我只知道如何读取访问令牌,但我不知道如何使用它来提取数据。我已经经历了无数的答案,其中大多数都谈论了一些语法,如 - >
“GET / oauth / access_token? CLIENT_ID = {应用ID} &安培; client_secret = {应用秘密} &安培; grant_type = client_credentials“
...我不知道。以下是我的代码 - >
$access_token = $facebook->getAccessToken();
$get_at = "https://graph.facebook.com/me?access_token=" . $access_token;
echo "Acess tokens in real!"; //i was just fooling here to print the token
echo "<br />" . $get_at;
$user_profile = $facebook->api('/me','GET');
echo "<pre>";
print_r($user_profile);
echo "</pre>";
$dost = $facebook->api('/me/friends','GET');
foreach ($dost['data'] as $value) {
$friend_id = $value['id'];
$events = $facebook->api('/' . $friend_id . '/events'); //this should have worked, but did not!
echo "<pre>";
echo "Friend Name: ";
print_r($value['name']);
echo "<br />";
echo "Friends events: ";
print_r($events);
echo "</pre>";
并且,我也使用了正确的权限! - &GT;
$params = array(
'scope' => 'public_profile, user_friends, email',
'redirect_url' => 'http://xxxxxxp.com'
);
$login_url = $facebook->getLoginUrl($params);
echo 'Please <a href="' . $login_url . '">login.</a>';
我很确定我错过了一些小事...... 任何想法,冠军?
答案 0 :(得分:0)
你遗失了许多东西。首先,您不是要求正确的权限。如果要阅读用户的事件,则需要请求user_events权限,如果要阅读朋友的事件,则需要在params数组的范围变量中请求friends_events权限:
$params = array(
'scope' => 'public_profile, user_friends, email, user_events, friends_events',
'redirect_url' => 'http://xxxxxxp.com'
);
$login_url = $facebook->getLoginUrl($params);
其次,您需要将检索到的访问令牌实际传递给api调用:
$events = $facebook->api('/' . $friend_id . '/events?access_token='. $get_at);