Reputation: 2951
I'm trying to read data from a Google Sheet via a Chrome extension leveraging Chrome Identity API, but I'm not even able to get an access token. This is what I've done so far:
manifest.json
to include:{
"permissions": [
"identity",
"https://docs.google.com/spreadsheets/"
],
"oauth2": {
"client_id": "<enter-oauth2-client-id-here>",
"scopes": [
"https://docs.google.com/spreadsheets"
]
}
}
console.log("here"); // this point is hit
var ci = chrome.identity;
ci.getAuthToken({ interactive: true }, function(token) {
console.log("token: " + token); // none of this is hit
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError);
return;
}
access_token = token;
});
At this point, when I reload the extension, Chrome asks me for my credentials (the ci.getAuthToken({ interactive: true } ...)
line is executed), but once the credentials are successfully provided, nothing else happens. I guess the token is never retrieved, which is why none of the code within function(token){...}
is executed. The background console shows the "here" message, but nothing else (no errors, warnings, or anything).
Note: In my manifest.json
, under oauth2:client_id
I'm using the OAuth2 client Id generated by the Google API Console.
What am I missing?
Upvotes: 0
Views: 3922
Reputation: 328
Maybe it's too late, but if anyone stumbles upon this post: regarding your CORS policy problem, you need to play with the content_security_policy
in your manifest.json
file, like so:
"content_security_policy": "script-src 'self' https://apis.google.com; object-src 'self'"
Upvotes: 0
Reputation: 7761
I think your scope for spreadsheet is incorrect. It should be https://www.googleapis.com/auth/spreadsheets
based on its documentation.
So change
"https://docs.google.com/spreadsheets"
to
"https://www.googleapis.com/auth/spreadsheets"
Upvotes: 1