I am trying to use chrome.identity.getAuthToken({ 'interactive': false }, function(token) {
in a script of the options_ui, but I can't get it to work. I need the oAuthToken to change Data in a Spreadsheet via API.
I added the chrome.identity.getAuthToken({ 'interactive': false }, function(token) {
when clicking on a save button of a pop-up in the options_ui, but I always get an error saying:
"Cannot read property getAuthToken of undefined"
.
options.js
which is included as a script in options.html
:
SaveButton.click(function () {
chrome.identity.getAuthToken({
interactive: true
}, function (token) {
console.log(token);
});
options.html
is included into manifest.json
:
"options_ui": {
"page": "options.html",
"open_in_tab": true},
}
I added the key and the clientID to my manifest.json
and I gave permissions to "identity"
as well.
"key": "MYKEY",
"oauth2": {
"client_id": "MyclientID.apps.googleusercontent.com",
"scopes":["https://www.googleapis.com/auth/spreadsheets"]
},
I could find out that it is not possible to use the API in a content_script. But as I'm using it in an options_ui, I suggest that this isn't the problem. I already spent a lot of time trying to figure out what causes the problem, but I wasn't able to make it work. Any other ideas? Maybe I didn't see something?
I already looked through other threads like this, but couldn't find any suitable solution.