用Python创建Google文档

用Python创建Google文档,python,google-authentication,Python,Google Authentication,我正在尝试使用GoogleAPI创建新的Google文档(用于请求审查的自动化) 我正在使用谷歌“示例”中的以下代码,但它对我不起作用: 执行此脚本时,出现错误: Traceback (most recent call last): File "google_docs.py", line 46, in <module> main() File "google_docs.py", line 31, in main 'credentials.json',

我正在尝试使用GoogleAPI创建新的Google文档(用于请求审查的自动化)

我正在使用谷歌“示例”中的以下代码,但它对我不起作用:

执行此脚本时,出现错误:

    Traceback (most recent call last):
  File "google_docs.py", line 46, in <module>
    main()
  File "google_docs.py", line 31, in main
    'credentials.json', SCOPES)
  File "/usr/local/lib/python3.7/site-packages/google_auth_oauthlib/flow.py", line 199, in from_client_secrets_file
    return cls.from_client_config(client_config, scopes=scopes, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/google_auth_oauthlib/flow.py", line 159, in from_client_config
    'Client secrets must be for a web or installed app.')
ValueError: Client secrets must be for a web or installed app.

所以,我想这意味着凭证文件是正确的,但我想知道我能做些什么来创建谷歌文档,而不仅仅是电子表格…

经过几个小时的实验和挫折,我发现了一个肮脏的解决办法:

import gspread
from googleapiclient.discovery import build


# The ID of a sample document.
DOCUMENT_ID = '195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE'

client = gspread.service_account(filename='credentials.json')

service = build('docs', 'v1', credentials=client.auth)
document = service.documents().get(documentId=DOCUMENT_ID).execute()
print('The title of the document is: {}'.format(document.get('title')))

因此,我将把它放在这里,以防有人会面临我今天遇到的同样问题:)

经过几个小时的实验和挫折,我找到了一个肮脏的解决办法:

import gspread
from googleapiclient.discovery import build


# The ID of a sample document.
DOCUMENT_ID = '195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE'

client = gspread.service_account(filename='credentials.json')

service = build('docs', 'v1', credentials=client.auth)
document = service.documents().get(documentId=DOCUMENT_ID).execute()
print('The title of the document is: {}'.format(document.get('title')))
所以,我会把它放在这里,以防万一有人会面临我今天遇到的同样问题:)