5

我在打包的应用程序中使用chrome.identity来获取使用Facebook的用户令牌。我调用chrome.identity.launchWebAuthFlow,并且需要将访问令牌发送给服务器,然后使用访问令牌来验证用户。如何获取Facebook令牌使用Oauth2与chrome.identity

适用于Google+。但由于某种原因,它不适用于Facebook。出于某种原因,Facebook的OAuth看起来很特别。我已将extensionid.chromiumapp.org添加到API中的重定向网址列表中。添加

"https://extensionid.chromiumapp.org/*", 
    "https://facebook.com/*", 
    "https://www.facebook.com/dialog/", 
    "https://graph.facebook.com/*" 

to 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."} » 

当我使用网址像

«"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令牌。我累了。我做错了什么? 为什么chrome.identity.getAuthToken适用于Google+和chrome.identity.launchWebAuthFlow不会与Facebook?

我希望有人做了同样的事情,可以帮助我。

+0

不提醒你什么?调用crome.identity.launchWebAuthFlow()时是否使用了“交互式”标志? –

+0

我使用 - chrome.identity.launchWebAuthFlow({'interactive':false,'url':authUrl},function(token){});和 - var authUrl =“https://www.facebook.com/dialog/oauth/access_token?"+ ”client_id = myclientId&client_secret = myclientSecret&“+ ”response_type = token“; – user3215200

+1

您是否尝试将“交互式”更改为true? –

回答

0

“需要用户交互”。消息意味着用户需要登录Facebook并/或批准所请求的OAuth范围。设置{interactive:true}标志将允许identity.launchWebAuthFlow显示用户将执行这些步骤的窗口。由于您传递{interactive:false}标志,因此identity.lauchWebAuthFlow失败。

https://www.facebook.com/dialog/oauth很可能是您想用来启动流程的网址。 client_credentials授权通常用于访问您的应用所拥有资源的情况,而不是特定用户拥有的资源。

但是,如果您确实想调试“授权页面无法加载”的情况,那么做法是打开chrome:// net-internals并查找从Facebook返回的错误响应。

0
chrome.identity.launchWebAuthFlow(
{'url': 'https://www.facebook.com/dialog/oauth?client_id=myclientid&redirect_uri=https://myextensionid.chromiumapp.org/facebook.com=token&scope=user, 'interactive': true}, 
function(redirect_url) { 
    /* Extract token from redirect_url */ 
    console.log(redirect_url); 
}); 

// '互动' 的例子: “需要用户干预” 真

what will this flag do, will show a dialog box asking username and password upon successful login it will ask for grant access just press that and you will receive redirect url in above function body.

相关问题