3 回答
TA贡献1111条经验 获得超0个赞
有一个如何使用InstalledAppFlow将 Google Docs 与 python 一起使用的示例:
from google_auth_oauthlib.flow import InstalledAppFlow
TA贡献1864条经验 获得超2个赞
按照评论和本教程(您可以从中受益以在控制台中创建应用程序),我实现了以下代码:
creds = None
# Check if previous log-in exists
if os.path.exists('/content/drive/MyDrive/Projects/xyz/token.pickle'):
with open('/content/drive/MyDrive/Projects/xyz/token.pickle', 'rb') as token:
creds = pickle.load(token)
# If not available or invalid, log in using the "console" InstalledAppFlow
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('/content/drive/MyDrive/Projects/xyz/credentials.json', SCOPES)
creds = flow.run_console()
# Save the access token in token.pickle file for the next run
with open('/content/drive/MyDrive/Projects/xyz/token.pickle', 'wb') as token:
pickle.dump(creds, token)
# Connect to the Gmail API
service = build('gmail', 'v1', credentials=creds)
添加回答
举报
