【发布时间】:2015-06-29 08:13:14
【问题描述】:
我遵循了这个问题中给出的答案 - chrome.identity User Authentication in a Chrome Extension
我安装了扩展并从 chrome://extensions 复制了密钥并生成了一个客户端 ID
生成客户端ID和应用程序ID后,我将它们粘贴到manifest.json
我的manifest.json -
{
"name": "Identity test",
"version": "1",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"permissions": [
"identity"
],
"oauth2": {
"client_id": "575910104810-bip578sprqmaauj7cred8ejsf3cirs95.apps.googleusercontent.com",
"scopes": [
"https://www.googleapis.com/auth/userinfo.email"
]
},
"key":"mebmekhndfhnahepihccnkiaifobgdbi"
}
我的background.js-
chrome.identity.getAuthToken({
interactive: true
}, function(token) {
if (chrome.runtime.lastError) {
alert(chrome.runtime.lastError.message);
return;
}
var x = new XMLHttpRequest();
x.open('GET', 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=' + token);
x.onload = function() {
alert(x.response);
};
x.send();
});
但我得到无效的 OAuth2 客户端 ID.Reason?
【问题讨论】:
标签: google-chrome-extension google-api