Google Sheets API Error code 400 API key not valid. Please pass a valid API key - google-sheets-api

I created a google cloud project and enabled the Google Sheets API. I created and API key that is restricted to Google Sheets API.
I am trying to access my sheet from this link: https://sheets.googleapis.com/v4/spreadsheets/${sheetId}/values/${sheetNameStr}?dateTimeRenderOption=FORMATTED_STRING&majorDimension=ROWS&valueRenderOption=FORMATTED_VALUE&key=${apiKey};
I am getting this error:
{
"error": {
"code": 400,
"message": "API key not valid. Please pass a valid API key.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "API_KEY_INVALID",
"domain": "googleapis.com",
"metadata": {
"service": "sheets.googleapis.com"
}
}
]
}
}
I have published the entire sheets doc as well as the specific sheet I want to access. The sheet is set up to be viewed by anyone who has the link.
I have tried other forms of the link, and it always comes back to this error. Any suggestions of where to go next is appreciated :)

Related

Google Sheets - "The caller does not have permission" exception

I am using v4 and google/apiclient:2.9.1 (php).
I successfully access the spreadsheet through oauth2. It is meaning I can read and edit data. But sometimes I get 403 http code with a body
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"errors": [
{
"message": "The caller does not have permission",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
for no apparent reason. I don't change the permissions of spreadsheet, don't revoke permissions, etc. Re-access request is successful and the data becomes available again through API.
Why it happens? How do I get rid of the need to re-request access permissions?
This is repeated on different accounts and spreadsheets.

403 Error creating dataSource for com.google.blood_pressure in Google Fit REST API

Goal:
I have a simple web application where I submit my Blood Pressure and Heart Rate measurements.
Now I'd like to submit these measurements to my Google Fit Account.
I tried Googles tutorial: https://developers.google.com/fit/scenarios/write-bp-data
OAuth2 Setup
I created new credentials in one of my existing Cloud Console Projects. And then requested a new authorization code using the following scopes (The project is in Testing State and my account is registered as tester):
https://www.googleapis.com/auth/fitness.blood_pressure.write
https://www.googleapis.com/auth/fitness.heart_rate.write
Requesting the token returns the following response:
{
"access_token": "ya29.XXXXXXXXXXXXXXXX",
"expires_in": 3599,
"refresh_token": "1//XXXXXXXXXXXXXXXX",
"scope": "https://www.googleapis.com/auth/fitness.heart_rate.write https://www.googleapis.com/auth/fitness.blood_pressure.write",
"token_type": "Bearer"
}
As you can see, both write scopes are granted.
Additionally, if I check the permissions in my Google Account, both scopes are set.
Create dataSource
Now I create two dataSources (one for com.google.heart_rate.bpm and one for com.google.blood_pressure).
creating the Heart Rate dataSource works as expected, but creating a dataSource for Blood Pressure returns a 403 PERMISSION_DENIED Error:
Request (POST https://www.googleapis.com/fitness/v1/users/me/dataSources)
{
"dataStreamName": "BPA-BloodPressure",
"type": "raw",
"application": {
"detailsUrl": "https://aaa.bbb.ccc",
"name": "Blood Pressure App",
"version": "1"
},
"dataType": {
"name": "com.google.blood_pressure"
}
}
Response
{
"error": {
"code": 403,
"message": "Scope not included to modify data of type com.google.blood_pressure. Possible scopes: https://www.googleapis.com/auth/fitness.blood_pressure.write",
"errors": [
{
"message": "Scope not included to modify data of type com.google.blood_pressure. Possible scopes: https://www.googleapis.com/auth/fitness.blood_pressure.write",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
The Google Fit REST API tells me that the Scope fitness.blood_pressure.write is missing, but as you can see the Scope is given for the used access token.
Notes
I am working with Postman to test all requests. Later a Java/Groovy or PHP backend will used.
I also tried with read and write scopes for both data types.
I can see my app with both write scopes in Google Fit under "Connected apps".
Change dataType name to "fitness.blood_pressure" instead of "com.google.blood_pressure"
The body will be like this.
{
"dataStreamName": "BPA-BloodPressure",
"type": "raw",
"application": {
"detailsUrl": "https://aaa.bbb.ccc",
"name": "Blood Pressure App",
"version": "1"
},
"dataType": {
"name": "fitness.blood_pressure"
}
}

Mimecast API authentication issue

trying to connect to endpoint with all needed headers defined:
https://us-api.mimecast.com/api/login/login.
Error message receieved : 0018 Client update required
Did anyone encounter/solve this issue?
{
"meta": {
"status": 401
},
"data": [],
"fail": [
{
"key": {
"username": "datadash#itprosusa.com",
"tokenType": "key",
"verifyOnly": false
},
"errors": [
{
"code": "err_xdk_client_update_required",
"message": "0018 Client update required",
"retryable": false
}
]
}
]
}
I came across the same error message when trying to get Access key and Secret Key. You can actually get these in the Mimecast portal UI by going to: Administration | Services | APIĀ Applications, then Add API Application fill in the details and wait 30 minutes. After 30 minutes click on your newly created API application and select Create Keys, fill in the required information and it will provide you with your Access key and Secret key used for API calls.
If this doesn't answer your question or help you I would suggest getting in contact with Mimecast Support, they are usually pretty good!

Google Sheets API not accepting my API Key

I generated an API key through Google Developer's Console. I am trying to read data from a Google Sheet.
However when I do a GET request using the following link:
https://sheets.googleapis.com/v4/spreadsheets/1nUeRttOMn--b46Vt7FIlU_eoOqvvuOyukAEg2L_UGQQ/values/A1%3AF500?key={abcdefghijklmnopqrstuvwxyz0123456789}`
I get the error message:
API key not valid. Please pass a valid API key.
Full error:
{
"error": {
"code": 400,
"message": "API key not valid. Please pass a valid API key.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developers console",
"url": "https://console.developers.google.com"
}
]
}
]
}
}
My API Key is valid. How can I resolve the error? I plan to make the API call via Alteryx.
Use this URL:
https://sheets.googleapis.com/v4/spreadsheets/PUT YOUR SHEET ID HERE/values/PUT YOUR SHEET NAME HERE (sheet name not spreadsheet name)?key=PUT YOUR API KEY HERE
I was going through the same error. The Key was valid and I even changed the keys but it was not working.
Here's what I did,
Before the error, it looked like this...
https://sheets.googleapis.com/v4/spreadsheets/PUT YOUR SHEET ID HERE/values/Sheet1?valueRenderOption=FORMATTED_VALUE&key=PUT YOUR API KEY HERE/HTTP/1.1
Then I removed the last bit and got the valid response.
https://sheets.googleapis.com/v4/spreadsheets/PUT YOUR SHEET ID HERE/values/Sheet1?valueRenderOption=FORMATTED_VALUE&key=PUT YOUR API KEY HERE
Worked like a charm!

I can not use Google Fusion Tables API

I'm trying to use the Google Fusion Tables API without success.
I created a table, set it to Public and I'm trying to access the API for my browser to this address:
https://www.googleapis.com/fusiontables/v1/query?sql=SELECT%20*%20FROM%201pheecBEHLRXeMA1cDSNGqhuXJ7srp9A3i1r3sdd6%20ORDER%20BY%20nome&key=my_key_access
But I always get this response:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
My table has registered data
What can be happening?
You must also enable the download-option for the table to be able to request data via the Fusion Tables API