need to know if i can call a specific part of the following script
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();
});
I currently use document.write(x.response) which writes out the users information but would like to call only the id
{ "id": "XXX",
"email": "XXX",
"verified_email": true,
"name": "XXX", }
what I would like to do is turn the id into a variable. var user_id = x.response['id']... Or something like that.
the original code can be found chrome.identity User Authentication in a Chrome Extension