如果我有用户的 oauth_token,如何获取他/她的 access_token?

发布于 2024-12-12 06:54:21 字数 170 浏览 2 评论 0原文

当用户打开我的画布应用程序时,我会从 Facebook 收到一个 signed_request,从中派生出 user_idoauth_token。我怎样才能获取access_token并检查/获取用户权限和其他数据?

When user opens my canvas app I get a signed_request from Facebook, from which I derive the user_id and oauth_token. How can I then get the access_token and check/get user permissions and other data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如歌彻婉言 2024-12-19 06:54:21

你所说的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/< /a>

以及有关在 API 中调用何处的所有信息在这里检索您需要的不同数据位 https://developers.facebook.com/docs/reference /api/

The oauth_token you're talking about is also the users access_token, they should be exactly the same.

To check the users permissions you can make a GET call to /me/permissions this should return a data array similar to the below

{
  "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"
    }
  ]
}

Depending on what the other data you wish to access you will need to ask for more permissions and then call the appropriate API end points. For example to get the users basic information make a call to /me or to get a list of their friends /me/friends

You can find all the permissions you can ask for at https://developers.facebook.com/docs/reference/api/permissions/

And all the information about where to call in the API for retrieving the different bits of data you require here https://developers.facebook.com/docs/reference/api/

假装不在乎 2024-12-19 06:54:21

当您说您拥有他们的“oauth 令牌”时,您确定这不是访问令牌吗?您可以尝试使用该令牌对 /me/permissions 进行 API 调用,看看它是否有效吗?它应该返回用户授予您的应用程序的权限列表(可通过该令牌使用)

When you say you have their 'oauth token' - are you sure that isn't the access token? Can you try making an API call to /me/permissions with that token and see if it's working? It should return a list of the permissions the user has granted your app (which are usable via that token)

夏有森光若流苏 2024-12-19 06:54:21
    <?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();
}




?>
    <?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();
}




?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文