Google Calendar API error - "API key not valid. Please pass a valid API key.",

Viewed 4766

I've started getting the error from google rest api since yesterday

{
  "error": {
    "code": 400,
    "message": "API key not valid. Please pass a valid API key.",
    "errors": [
      {
        "message": "API key not valid. Please pass a valid API key.",
        "domain": "global",
        "reason": "badRequest"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }
}

API endpoint is: https://www.googleapis.com/calendar/v3/calendars/[CALENDAR_ID]/events?timeMax=2020-06-22T23%3A59%3A59.000%2B06%3A00&timeMin=2020-06-22T00%3A00%3A00.000%2B06%3A00&key=[SECRET_KEY]

headers are:

"Content-length"    "0"
"Content-Type"  "application/x-www-form-urlencoded"
"Host"  "www.googleapis.com"
"Authorization" "Bearer [APPILCATION_ID]"
"Accept"    "application/json"

I have oAuth 2.0 client id in developer console. And send the same request as 3 month before What may be wrong?

1 Answers

API key not valid. Please pass a valid API key.

Means that the api key you are using is not valid.

Go to Google developers console select your project.

Click Credentials in the menu on the left

click the + create credentials at the top and select API key.

enter image description here

bearer token

"Authorization" "Bearer [APPILCATION_ID]"

Please not that the bearer token sent should be a valid non expired access token. Not an application id.

Note

Api keys are used for accessing public data like all the holiday calendars make sure that the calendar id you are trying to access is set to public if you want to be able to request data from it.

If this is a user calendar you will need to switch to using Oauth2 and request that they grant you permission to access their data.

If this is your own calendar and you want to allow others to see the data then you should consider using a service account.

Related