我正在为 OS X 构建一个小型 Facebook 登录库。这并不是因为没有 SDK,而是因为我想要 Cocoa 原生的东西来封装登录过程。我已成功从 Facebook 登录 URL 请求访问 token 。我使用此字符串格式来执行登录:
https://www.facebook.com/dialog/oauth?client_id=%@&redirect_uri=%@&response_type=token
对于 redirect_uri
字段,我按照 Facebook 文档传递 https://www.facebook.com/connect/login_success.html
。我接受该响应并解析 URL。我要么得到一个 token ,要么失败。 token 似乎回来了。麻烦出在下一步。
收到我的 token 后,我立即尝试验证它。我使用“调试”端点,如下所示:
https://graph.facebook.com/debug_token?input_token=%@&access_token=%@
我将新 token 作为 input_token
传递,这就是它变得粘性的地方。我尝试传递我的客户端 token ,但这会导致以下错误:
The operation couldn’t be completed. (Invalid OAuth access token. error 190.)`
如果我传递我的应用程序 ID |应用程序 secret
,我收到不同的错误:
The operation couldn’t be completed. ((#100) You must provide an app access token or a user access token that is an owner or developer of the app error 100.)
我不确定这里发生了什么,或者该怎么办。谁能指出我正确的方向?
最佳答案
debug API 适用于您希望以应用程序而非用户身份执行操作的情况。用户登录后,您所需要的只是他们的访问 token 来获取有关他们的信息,阅读他们的信息,发布内容(当然,假设您拥有一个有权执行您想要执行的操作的访问 token )。因此,就您而言,现在您已经有了访问 token ,请继续尝试使用获取有关用户的信息
https://graph.facebook.com/me?access_token=%@
你会得到这样的结果:
{
"id": "542440888",
"name": "Max Rabin",
"first_name": "Max",
"last_name": "Rabin",
"link": "https://www.facebook.com/MY_USER_NAME",
"username": "MY_USER_NAME",
"birthday": "11/22/YEAR",
"hometown": {
"id": "110970792260960",
"name": "Los Angeles, California"
},
"location": {
"id": "110970792260960",
"name": "Los Angeles, California"
},
"bio": "There are 10 kinds of people in this world.\r\n01: Those who know trinary\r\n02: Those who don't\r\n10: Those who confuse it with binary",
"gender": "male",
"email": "MY_EMAIL",
"timezone": 2,
"locale": "en_US",
"languages": [
{
"id": "106059522759137",
"name": "English"
}
],
"verified": true,
"updated_time": "2013-10-21T10:02:49+0000"
}
关于cocoa - 验证 Facebook token 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19688494/