gpt4 book ai didi

python - 如何使用 google api 和 python 在 google 文档中打开文件?

转载 作者:行者123 更新时间:2023-12-01 07:17:22 25 4
gpt4 key购买 nike

我尝试打开由 python/django 编写的应用程序发送的文件。使用文档 link为了创建空白文档,我尝试传输现有文件以在 Google 文档中打开。

views.py

SCOPES = ['https://www.googleapis.com/auth/documents.readonly']
def file_to_gd_docs(import_file=None):
....
#authorization part(success)
....
service = build('docs', 'v1', credentials=creds)

title = 'My Document'
body = {
'title': title
}
doc = service.documents().create(body=import_file).execute()
print('Created document with title: {0}'.format(
doc.get('title')))

我将import_file的值作为变量body的值我收到一个错误

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://docs.googleapis.com/v1/documents?alt=json returned "Request had insufficient authentication scopes.">

如何正确地将外部文件传输到 Google 文档以供打开?

最佳答案

Documents.create需要以下范围之一

enter image description here

您正在使用https://www.googleapis.com/auth/documents.readonly,这会给您带来错误

Request had insufficient authentication scopes.

解决方案

将范围更改为所需的范围之一,并再次请求用户访问。

关于python - 如何使用 google api 和 python 在 google 文档中打开文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57890229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com