我想在开始扩展后通过Google授权。
我写下了manifest.json和background.js,如下所示。
当前目录结构
的manifest.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"
}
}
background.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);
}
});
安装并运行后,无法加载输出日志'授权页面。'。
<{1}}内的{p>redirect_url
未定义。
如果你知道我的错误,请教我。
答案 0 :(得分:2)
您的清单中没有the key
。
您需要copy your extension's key清单。
当您在Google OAuth控制台中注册应用程序时,您将会这样做 提供您的应用程序ID,将在令牌期间进行检查 要求。因此,拥有一致的应用程序ID非常重要 在开发过程中。
要使应用程序ID保持不变,您需要复制密钥 将manifest.json安装到源清单。