调用Google Calendar API时出现keyInvalid错误 [英] keyInvalid Error when calling Google Calendar API

查看:198
本文介绍了调用Google Calendar API时出现keyInvalid错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写查询Google日历事件的Lambda函数.尽管我在Google Developers Console上成功创建了凭证(客户端ID和客户端密钥),但是我无法访问事件.错误:

I'm writing a Lambda function that queries Google Calendar events. Although I successfully created a credential (client ID, and client secret) on Google Developers Console, I cannot access the events. Error:

{错误":{错误":[{域":"usageLimits",原因":"keyInvalid",消息":错误的请求"}],代码":400,消息:错误请求"}}

{ "error": { "errors": [{ "domain": "usageLimits", "reason": "keyInvalid", "message": "Bad Request" } ], "code": 400, "message": "Bad Request" } }

我的http请求看起来像这样: https://www.googleapis.com/calendar/v3/日历/MY_CLIENT_ID/事件?key = MY_CLIENT_SECRET

My http request looks like this: https://www.googleapis.com/calendar/v3/calendars/MY_CLIENT_ID/events?key=MY_CLIENT_SECRET

出了什么问题?任何帮助将不胜感激.

What went wrong? Any help is greatly appreciated.

推荐答案

"domain":"usageLimits","reason":"keyInvalid","message":"Bad Request"

"domain": "usageLimits", "reason": "keyInvalid", "message": "Bad Request"

表示您发送的密钥是无效的api密钥.

Means that the key you are sending is an invalid api key.

背景信息

当您向Google api请求公共数据时,可以使用API​​密钥.公开数据是用户不拥有的数据.例如google +上的公开帖子,google图书.在这些情况下,您可以使用api键来使用

When you make a request to a Google api for public data you can use an API key. Public data is data that is not owned by a user. For example public posts on google+, google books. In these instances you can use an api key inorder to access the api using

GET https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=25&q=surfing&type=test&key={YOUR_API_KEY}

键使用您在Google开发人员控制台中创建的api键将您的应用程序标识为google.

key identifies your application to google using the api key you create in google developer console.

私人数据是用户拥有的数据,例如您的Google日历,应用程序在没有权限的情况下无法向其发布数据.为此,我们使用 Oauth2 .您可以在Google Developer Console上创建客户端,然后使用oauth2登录用户.您将获得访问令牌,然后您可以提出请求

Private data is data that is owned by a user for instance your google calendar an application can not post to it with out permissions. Inorder to do this we use Oauth2. You create a client on google developer console then login the user using oauth2. you will get an access token back then you can make a request

https://www.googleapis.com/calendar/v3/calendars/MY_CLIENT_ID/events?accesstoken=ACCESSTOKEN

请注意,第一个请求使用了密钥,第二个请求使用了访问令牌.

Notice that the first request used key and the second used accesstoken.

答案

您的问题是,您正在发送客户端密钥作为api密钥,该密钥将不起作用,因为首先,客户端密钥不是api密钥,而第二个事件是私有用户数据,需要您首先对用户进行身份验证.

Your problem is that you are sending a client secret as an api key which will not work because first of all a client secret is not an api key and second events are private user data which will require that you authenticate your user first.

这篇关于调用Google Calendar API时出现keyInvalid错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆