【问题标题】:Access tokens?访问令牌?
【发布时间】:2012-05-07 17:38:25
【问题描述】:

我正在开发一个托管在 Heroku 上的 PHP 应用程序,我最大的问题是没有为用户获取访问令牌以使我的应用程序完全运行。该应用程序非常适合我(因为我是管理员),但与该应用程序无关的其他人无法让该应用程序显示任何内容。我还尝试使用测试用户来查看它是否可以工作,但仍然没有运气。我很确定这与访问令牌和应用程序无权执行其操作有关。我该如何以及在哪里解决这个问题?

【问题讨论】:

  • 您能否发布您用于获取 access_tokens 的代码,请不要包含您的密钥。
  • 我认为我什至没有在我的代码中的任何地方获得访问令牌。
  • 我应该在哪里设置访问令牌?
  • 如果你还没有读过这篇文章,你可能应该读一下:developers.facebook.com/docs/authentication

标签: access-token facebook-authentication facebook-access-token


【解决方案1】:

for user access_token我使用,其中数字是应用程序ID。


if($_SESSION['fb_135669679827333_access_token']){
$access_token = $_SESSION['fb_135669679827333_access_token'];
}

对于应用程序访问令牌,我使用 cURL。返回结果类似于 access_token=xxxxxxxxxx 使用喜欢 - /anotherfeed/feed?$app_access_token


$app_access_token = GetCH();
function GetCH(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=SECRET_KEY&grant_type=client_credentials");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
if(substr($url,0,8)=='https://'){
    // The following ensures SSL always works. A little detail:
    // SSL does two things at once:
    //  1. it encrypts communication
    //  2. it ensures the target party is who it claims to be.
    // In short, if the following code is allowed, CURL won't check if the 
    // certificate is known and valid, however, it still encrypts communication.
    curl_setopt($ch,CURLOPT_HTTPAUTH,CURLAUTH_ANY);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
}
$sendCH = curl_exec($ch);
curl_close($ch);
return $sendCH;
};

【讨论】:

    猜你喜欢
    • 2011-12-31
    • 2019-11-11
    • 2019-12-08
    • 2012-04-12
    • 2018-07-27
    • 2019-03-22
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多