Reputation: 61
I'm trying to make an extencion that will take some data from page and send it to google sheet. My manifest:
"oauth2": {
"client_id": "client_id",
"scopes": ["https://www.googleapis.com/auth/spreadsheets"]
},
"permissions": [
"activeTab",
"tabs",
"https://*.*/*",
"storage",
"declarativeContent",
"identity",
"https://ssl.gstatic.com/",
"https://www.googleapis.com/*",
"https://accounts.google.com/",
"https://sheets.googleapis.com/",
"https://www.googleapis.com/auth/spreadsheets/"
],
"key": {key}
background page:
var tokenS;
chrome.runtime.onInstalled.addListener(function() {
chrome.storage.sync.set({number: value}, function(data) {
});
chrome.identity.getAuthToken({
interactive: false
}, function(token) {
tokenS = token
console.log(token)
});
});
function writeData(request, sender){
myspreadsheetId = "myspreadsheetId "
var params = {
"range":"Sheet1!A1:A",
"majorDimension": "ROWS",
"values": [
[request.name]
],
}
var xhr = new XMLHttpRequest();
xhr.open('PUT', 'https://sheets.googleapis.com/v4/spreadsheets/' + myspreadsheetId + '/values/Sheet1!A1:A1?valueInputOption=USER_ENTERED');
console.log(tokenS)
xhr.setRequestHeader('Authorization', 'Bearer '+tokenS);
xhr.send(JSON.stringify(params));
};
chrome.runtime.onMessage.addListener(writeData)
I receive next error:
{
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"status": "PERMISSION_DENIED"
}
}
at google cloud platform I see a 100% error ratio (http://prntscr.com/jvfl0c). And I do not understand what I'm doing wrong. Pleasse help.
Upvotes: 2
Views: 27707
Reputation: 1
that is case sensitive please check it whether it is Key or key
Upvotes: 0
Reputation: 39
You're meant to replace the second 'key' in "key": {key}
(on the last line of the first code sample) with an API Key you've generated for your project in the Google Cloud Console.
To Generate your API Key you need to navigate to the credentials page and click on create credentials >> API key.
Firstly, ensure that your project of choice is selected Example
Next; from the 'Navigation Menu' >> 'APIs & Services' >> 'Crendentials' >> 'Create Credentials' >> 'API key'
Upvotes: 3