python - Google Calendar API 对 token.json 的理解

标签 python google-oauth google-calendar-api google-api-python-client

我正在使用 Google 日历 API,特别是 python 快速入门,但语言并不重要。

来自 https://developers.google.com/calendar/api/quickstart/python 的示例有:

 if not creds or not creds.valid:
    if creds and creds.expired and creds.refresh_token:
      creds.refresh(Request())
    else:
      flow = InstalledAppFlow.from_client_secrets_file(
          "credentials.json", SCOPES
      )
      creds = flow.run_local_server(port=0)
    # Save the credentials for the next run
    with open("token.json", "w") as token:
      token.write(creds.to_json())

我正在开发一个网站,主要是服务器端。人们将登录并能够创建日历,服务器将允许他们创建日历,并根据发生的事件自动添加事件。

问题1: 我的问题是关于 token.json 的,该文件是在所有用户之间共享的,还是应该为每个人创建一个分隔 rune 件?

问题2: 是否应该备份,因为如果我丢失了文件,那么每个人都会被注销吗?

最佳答案

Question 1: My question is about token.json, is that file shared between all users, or should a separator file be created for each person?

Token Json 是单用户的。事实上,当您编写代码时,它是单用户的。 示例所做的第一件事是检查文件是否存在

if os.path.exists("token.json"):

如果是,它将加载该文件中的凭据。

Question 2: Should it be backed up, cause if I lost the file then will everyone be logged out?

是的,您可能应该备份它,因为授权该应用程序的用户将被提示再次授权您的应用程序。注意这是授权而不是认证,没有注销

注释:

您正在关注的代码 Authorize credentials for a desktop application它是为桌面应用程序设计的,正如所写的那样,它是单用户的。

它也无法在托管网页上运行。

flow = InstalledAppFlow.from_client_secrets_file(
      "credentials.json", SCOPES
  )
  creds = flow.run_local_server(port=0)

将在其运行的计算机上运行授权请求,除非用户可以登录到网络服务器,否则它不会工作。

关于python - Google Calendar API 对 token.json 的理解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77522673/

相关文章:

spring-boot - 为什么 OAuth2UserService 没有在 WebSecurityConfigurerAdapter 下的 Spring Boot 中运行角色授权?

javascript - Google 日历错误地从 .ics 文件导入事件

python - 来自 QWidget 的 "Must construct a QApplication before a QPaintDevice"

android - 使用 Google 身份验证更改生产应用程序的 Firebase 项目?

java - Gmail Api 请求的身份验证范围不足

google-calendar-api - 有没有办法以编程方式将ICS导入Google日历?

javascript - 在谷歌日历 API events.list 的响应中查找日历所有者的电子邮件?

python - 如何将 Pandas Dataframe 偏移/移动到另一年?

python - 重用requests_oauthlib授权

python - Urwid 水平菜单 - 返回上一个状态或重新开始循环