我按照这个问题给出的答案 - 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。原因?