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

痴心易碎 提交于 2020-08-10 05:48:11

问题


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:


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.

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.



来源:https://stackoverflow.com/questions/62527656/google-calendar-api-error-api-key-not-valid-please-pass-a-valid-api-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!