Ive searched high and low for an answer to this on here but havent been able to find anything. Please answer if you can, its appreciated.
The Setup:
Im learning how to work with the PHP Facebook API SDK by using one of the examples as a base. Im new to working with APIs so Im a little confused and have been having a problem trying to list a users groups.
The Question:
Ive got the app made. Ive got the proper permissions and extended permissions. I am able to get the users name and basic info.
我认为我的问题在于访问获取用户组所需的扩展权限所需的访问令牌。我不确定我是否正确地将其发送到 API。
这就是我得到的:
<?
if($user_id) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
$access_token = $facebook->getAccessToken();
$user_profile = $facebook->api('/me','GET');
$user_groups = $facebook->api('/me/groups','GET', array( 'access_token=' => $access_token ));
echo "Name: " . $user_profile['name'];
echo "<br />";
echo "Groups: " . $user_groups['name'];
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$args['scope'] = 'user_groups,user_likes';
$login_url = $facebook->getLoginUrl($args);
echo 'Please <a href="' . $login_url . '">login.</a>';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
// No user, print a link for the user to login
$args['scope'] = 'user_likes,user_groups';
$login_url = $facebook->getLoginUrl($args);
echo 'Please <a href="' . $login_url . '">login.</a>';
}
?>
任何帮助表示赞赏。
谢谢。