Mas*_*nou 4 javascript google-chrome google-chrome-extension
我想在开始扩展后向 Google 授权。
我编写的manifest.json和background.js如下。
当前目录结构
清单.json
{
"manifest_version": 2,
"name": "***************",
"short_name": "DSBOT",
"version": "0.0.1.0",
"description": "**************************",
"icons": {
"16": "images/icon_16.png",
"48": "images/icon_48.png",
"128": "images/icon_128.png"
},
"background": {
"scripts": [
"background.js"
]
},
"browser_action": {
"default_icon": {
"19": "images/icon_19.png"
},
"default_popup": "popup.html"
},
"permissions": [
"identity",
"http://*/*",
"https://*/*",
"storage"
],
"oauth2": {
"client_id": **************,
"scopes": ["openid", "email", "profile"],
"hd": "zabuton.co.jp"
}
}
Run Code Online (Sandbox Code Playgroud)
背景.js
var clientId = "********************";
var redirectURL = chrome.identity.getRedirectURL();
var url = "https://accounts.google.com/o/oauth2/v2/auth?" +
"scope=email&" +
"response_type=token&" +
"client_id=" + encodeURIComponent(clientId) + "&" +
"redirect_uri=" + encodeURIComponent(redirectURL) + "&" +
"prompt=consent";;
chrome.identity.launchWebAuthFlow({ url: url, interactive: true }, function(redirect_url) {
console.log('redirect_url = ' + redirect_url);
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError.message);
}
});
Run Code Online (Sandbox Code Playgroud)
安装并运行后,输出日志“无法加载授权页面。”。
redirect_url里面launchWebAuthFlow是未定义的。
如果你知道我的错误,请教我。
你的清单中没有这个。key
您需要将扩展程序的密钥复制到清单中。
当您在 Google OAuth 控制台中注册应用程序时,您将提供应用程序的 ID,该 ID 将在令牌请求期间进行检查。因此,在开发过程中拥有一致的应用程序 ID 非常重要。
为了保持应用程序 ID 不变,您需要将已安装的 manifest.json 中的密钥复制到源清单中。
| 归档时间: |
|
| 查看次数: |
4163 次 |
| 最近记录: |