我在打包的应用程序中使用 chrome.identity 来获取使用 Facebook 的用户 token 。我调用 chrome.identity.launchWebAuthFlow,我需要获取访问 token ,将其发送到服务器,然后使用访问 token 来验证用户。
与 Google+ 配合得很好。但出于某种原因,它不适用于 Facebook。出于某种原因,Facebook 的 OAuth 似乎很特别。我已将 extensionid.chromiumapp.org 添加到 API 中的重定向 URL 列表中。添加了
"https://extensionid.chromiumapp.org/*",
"https://facebook.com/*",
"https://www.facebook.com/dialog/",
"https://graph.facebook.com/*"
到 manifest.json。但是什么都没有改变。
在调用 chrome.identity.launchWebAuthFlow 时,我使用这样的 URL
"https://www.facebook.com/dialog/oauth/access_token?" +
"client_id=myclientid&client_secret=myclientsecret&" +
"response_type=token&grant_type=client_credentials"
当我尝试调用它时,我收到以下错误消息:
«launchWebAuthFlow completed Object {message: "Authorization page could not be loaded."} »
当我使用像
这样的 URL 时«"https://www.facebook.com/dialog/oauth?client_id=myclientid&redirect_uri=https://myextensionid.chromiumapp.org/facebook.com=token&scope=user"»
我得到下一个错误:
«launchWebAuthFlow completed Object {message: "User interaction required."} undefined »
我尝试在 4 天内获得 facebook token 。我累了。我做错了什么? 为什么 chrome.identity.getAuthToken 适用于 Google+ 而 chrome.identity.launchWebAuthFlow 不适用于 Facebook?
我希望有人做过同样的事情并且可以帮助我。
最佳答案
我已经解决了这个问题。这是一个例子 https://github.com/blackgirl/Facebook_Oauth2_sample_for_extensions
关于javascript - 如何使用带有 chrome.identity 的 Oauth2 获取 Facebook token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21312547/