python - 使用 Google Calendar API 时“Safari 无法连接到服务器”
问题描述
所以我正在使用谷歌日历 API,我可以登录,但是一旦我打开应用程序,它就无法加载页面。
这是我的代码
from pprint import pprint
import datetime
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
CLIENT_SECRET_FILE = "client_secret.json"
API_NAME = "calendar"
API_VERSION = "v3"
SCOPES = ["https://www.googleapis.com/auth/calendar"]
creds = None
if os.path.exists("token.json"):
creds = Credentials.from_authorized_user_file("token.json", SCOPES)
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(CLIENT_SECRET_FILE, SCOPES)
creds = flow.run_local_server(port=8080)
# Save the credentials for the next run
with open("token.json", "w") as token:
token.write(creds.to_json())
service = build("calendar", "v3", credentials=creds)
解决方案
推荐阅读
- java - 关于 ehcache 配置的休眠升级后的堆栈跟踪
- python - 获取所有一个字符的字符串?
- amazon-web-services - 解析参数“--expression-attribute-values”时出错:JSON 无效:需要用双引号括起来的属性名称:第 1 行第 3 列(字符 2)
- php - 将 2 个数组 x 3 key=> value 转换为 3 个数组 x 2 [index] value
- windows - 命名一个Xming窗口并自动杀死
- c# - 要显示最多 5 个缩略图
- visual-studio - 如何使用 FileCodeModel 检测 VB 中枚举值的属性
- javascript - 在 HTML5 画布上使用 drawImage 函数时接收无法读取 null 的属性“getContext”
- php - php在phpmyadmin中生成查询显示错误
- mysql - 在 mySQL(工作台或 cmd)中返回具有多个查询的多个表集