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.

相關問題