格式错误的Facebook访问令牌 [英] Malformed Facebook Access Token

查看:95
本文介绍了格式错误的Facebook访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Facebook Graph API从Facebook抓取相册并将其放置在我正在工作的网站上.我使用PHP作为Codeigniter框架的语言,并重定向到Facebook URL以获取用户的访问令牌. Facebook将访问令牌返回给我,我抓住它并将其插入到数据库中.

I'm trying to use the Facebook Graph API to grab photo albums from Facebook and place them on a website I'm working on. I am using PHP as my language with the Codeigniter framework and am redirecting to a Facebook URL to get an access token for the user. Facebook returns an access token to me and I grab it and insert it into my database.

也就是说,当我尝试通过转到图形URL来获取相册的JSON数据时,它将返回错误.图形网址和错误为:

That being said, when I try to grab the JSON data for the photo album by going to to a the graph URL, it returns an error. The graph URL and error are:

https://graph.facebook.com/1298926000574/photos?access_token=[MY ACCESS TOKEN]

My access token: AQBxqdB64GHNTGY5Yp_IOuMY7NerwNtXVVrp2HwT1qXj02zqU-63KJDyB2jzqurlJ4M0vd7TAu7upA6T7ZYQzIChr2PgD1dpu-6Iebi0WVILbBSBOu-yj7sgcHSGS-Ew4Yio0I9In-1O5jOxbYLDMbI0Zmwk-F1-u-7a8iVvTJram8PvpmdRt5eg

Returned error:

{
"error": {
  "message": "Malformed access token [MY ACCESS TOKEN]",
  "type": "OAuthException",
  "code": 190
}
} 

我真的不确定Facebook为什么不断向我返回此错误.访问令牌很长,我将其作为文本"字段存储在数据库中.我听了他们的指示,现在他们在朝我开枪.任何帮助将不胜感激.

I'm really unsure why Facebook keeps returning this error to me. The access token is quite long and I'm storing it in my database as a "text" field. I followed their instructions and now they are shooting me in the foot. Any help would be much appreciated.

推荐答案

我遇到了同样的问题,我发现这篇文章正在寻找解决方案.我注意到我们的"访问令牌有很多奇数符号,而其他的只是字母数字字符串.

I had this same problem and I found this post searching for a solution. I noticed that 'our' access token had a lot of odd symbols, while others are just an Alphanumeric string.

我相信您(和我)犯的错误是将代码 access_token

I believe that the mistake you (and I) made was mixing the code with the access_token

将facebook用户发送到您的api以确认访问权限后,他们会使用$_GET['code']返回到您的网站.此代码需要通过Facebook进行验证,Facebook将会在成功后返回 access_token .

After sending the facebook user to your api to confirm access, they get returned to your website with $_GET['code']. This code needs to be verified with Facebook, who will return the access_token on success.

$app_id = [YOUR_APP_ID];
$app_secret = [YOUR_APP_SECRET];
$my_url = [THE_SAME_AS_THE_POST_BEFORE];
$code = $_GET['code'];

$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret . "&code=" . $code;

$response = file_get_contents($token_url);
$params = null;
json_decode($response, $params);
$access_token = $params['access_token'];

有关使用PHP获取访问令牌的更多信息

有关使用正确的redirect_uri的更多信息

这篇关于格式错误的Facebook访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆