通过POST请求进行Google Calendar api身份验证

编程入门 行业动态 更新时间:2024-10-26 08:25:51
本文介绍了通过POST请求进行Google Calendar api身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试向Google日历api发出POST请求,但我不明白如何进行身份验证.

I am trying to issue a POST request towards the google calendar api, but I fail to understand how to authenticate it.

我采取了以下步骤尝试并使用服务帐户来这样做:

I took the following steps to try and use a service account to do so:

  • 我已在Google Cloud控制台中启用了日历api
  • 我创建了一个新的服务帐户,启用了 G Suite域范围委派,并下载了提供的密钥.
  • 我已将服务帐户电子邮件添加到日历中,以便能够进行更改和创建事件.
  • 我已尝试创建对 www的POST请求.googleapis/calendar/v3/calendars/ calendarId /events,其中JSON密钥的内容作为 Authorization 标头的值,但我收到了以下错误:

  • I've enabled the the calendar api in the Google Cloud console
  • I've created a new service account, enabled G Suite Domain-wide Delegation, and downloaded the provided key.
  • I've added the service account email to the calendar to be able to make changes and create events.
  • I've tried to create a POST request to www.googleapis/calendar/v3/calendars/calendarId/events with the contents of the JSON key as the value of the Authorization header, but I receive the following error:

    {错误": {错误":[{"domain":"global","reason":"authError","message":无效的凭证","locationType":"header",位置":授权"}],代码":401,"message":无效的凭据"}}

    我是否缺少某些步骤,或者我不正确理解身份验证过程?非常感谢您的帮助.

    Am I missing some steps or have I do not understand correctly the authentication process? I would appreciate your help.

    推荐答案

    不仅仅是将密钥文件的内容应用于您的调用,所有Google api都需要访问令牌才能对其进行身份验证.

    Its not simply a matter of applying the contents of the key file to your call, all google apis need an access token in order to authenticate them.

    要从服务帐户获取访问令牌,您需要执行以下步骤.准备进行授权的API调用

    To get an access token from a service account you need to follow the following steps. Preparing to make an authorized API call

    您需要完成一些步骤才能获得调用api所需的访问令牌

    There are steps you will need to complete inorder to get the access token you will need to make a call to the api

    从API控制台获取客户端ID和私钥后,您的应用程序需要完成以下步骤:

    After you obtain the client ID and private key from the API Console, your application needs to complete the following steps:

  • 创建一个JSON Web令牌(JWT,发音为"jot"),其中包括标头,声明集和签名.
  • 从Google OAuth 2.0授权服务器请求访问令牌.
  • 处理授权服务器返回的JSON响应.
  • 我建议您选择自己喜欢的服务器端编程语言并为其找到客户端库.这样一来,您便可以尝试轻松地使用服务帐户进行身份验证了.

    I recommend you pick your favorite server sided programming language and find a client library for it. It will make things much easier then you trying to authncate using a service account by yourself.

    更多推荐

    通过POST请求进行Google Calendar api身份验证

    本文发布于:2023-10-10 01:21:23,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1477296.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:身份验证   Google   POST   api   Calendar

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!