当用户打开我的画布应用程序时,我从Facebook获得signed_request
,我从中获得user_id
和oauth_token
。如何获取access_token
并检查/获取用户权限和其他数据?
答案 0 :(得分:5)
您所谈论的oauth_token也是用户access_token,它们应该完全相同。
要检查用户权限,您可以对/ me / permissions进行GET调用,这应该返回类似于下面的数据数组
{
"data": [
{
"installed": 1,
"read_stream": 1,
"manage_notifications": 1,
"manage_pages": 1,
"user_likes": 1,
"user_activities": 1,
"user_interests": 1,
"user_photos": 1,
"user_about_me": 1,
"type": "permissions"
}
]
}
根据您希望访问的其他数据,您需要获得更多权限,然后调用相应的API端点。例如,要向用户提供基本信息,请拨打/me
或获取他们的朋友列表/me/friends
您可以在https://developers.facebook.com/docs/reference/api/permissions/
找到您可以要求的所有权限有关在API中调用的位置的所有信息,用于检索您在此处所需的不同数据位https://developers.facebook.com/docs/reference/api/
答案 1 :(得分:1)
当你说你有'oauth令牌'时 - 你确定那不是访问令牌吗?您是否可以尝试使用该令牌对/me/permissions
进行API调用,看看它是否正常工作?它应该返回用户授予您的应用程序的权限列表(可通过该令牌使用)
答案 2 :(得分:-1)
<?php
include '../../src/config.php';
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
$access_token = $facebook->getAccessToken();
$user_xml = "<?xml version=\"1.0\"?>\n";
$user_xml .= "<roots>\n";
$user_xml .= "<access>\n";
$user_xml .= "<token>" . $access_token . "</token>\n";
$user_xml .= "</access>\n";
$user_xml .= "</roots>\n";
echo $user_xml;
} else {
$loginUrl = $facebook->getLoginUrl();
}
?>