heroku 如何访问Google Calendar API Bearer auth token?

ergxz8rk  于 2023-05-18  发布在  Go
关注(0)|答案(1)|浏览(318)

我试图设置Google Calendar API push notifications,但我不知道如何访问我在对watch方法的POST请求中需要的auth_token_for_current_user。我如何访问它?
我问的是授权头中Bearer之后的auth令牌部分。
POST https://www.googleapis.com/calendar/v3/calendars/my_calendar@gmail.com/events/watch授权:当前用户的承载认证令牌
内容类型:应用程序/json
如果重要的话,我的注册域名是一个heroku示例。而且我知道如何在通过javascript quickstart tutorial后检索日历事件信息。

cnjp1d6j

cnjp1d6j1#

我正在使用Python,但也许有人仍然需要它。
如果您也尝试通过此方法访问:https://developers.google.com/calendar/api/quickstart/python那么我的回答可能会对你有所帮助。
然后,在成功运行quickstart.py脚本后,您将拥有一个token.js文件。“token”-是您的auth_token_for_current_user。他在每次使用oAuth2登录时生成。如果我哪里说错了请纠正我。我对这个主题很陌生
P.S.我不确定你是否能在js上得到一个token.json文件,但那里可能有类似的东西。
如果您尝试使用OAuth 2.0 Playground提交请求,它最终会看起来像这样:

POST /calendar/v3/https://www.googleapis.com/calendar/v3/calendars/my_calendar@gmail.com/events/watch/watch HTTP/1.1
Host: www.googleapis.com
Content-length: 110
Content-type: application/json
Authorization: Bearer auth_token_for_current_user
{
  "id": "AnythingCanBeEntered", 
  "type": "web_hook",
  "address": "https://mydomain_com/notifications",
}

my_calendar@gmail.com可以从您的谷歌日历设置->日历ID中获取

相关问题