Google API Python Script凭据错误

发布于 2025-01-29 16:02:43 字数 1510 浏览 3 评论 0原文

我想将我的CSV文件添加到我的Google驱动器表中,最终得到了此脚本:

import gspread
import os.path
from google.oauth2.credentials import Credentials
from oauth2client.service_account import ServiceAccountCredentials

#scope = ['https://www.googleapis.com/auth/spreadsheets']
#scope = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/spreadsheets',
#         "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]


#scopes = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/spreadsheets',
#         "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]
scopes = ['https://www.googleapis.com/auth/spreadsheets']

if os.path.exists('token.json'):
        creds = Credentials.from_authorized_user_file('token.json', scopes) #credentials.json?
client = gspread.authorize(creds)

spreadsheet = client.open('Database-TTF')

with open('newTTF-Projects-INFO.csv', 'r') as file_obj:
    content = file_obj.read()
    client.import_csv('1gv-bKe-flo5FwIbt_xgCp1vNn0L0KBnpiuRak9a1efQ', data=content)

但是不幸的是我有一个错误:

APIError: {'errors': [{'domain': 'global', 'reason': 'insufficientPermissions', 'message': 'Insufficient Permission: Request had insufficient authentication scopes.'}], 'code': 403, 'message': 'Insufficient Permission: Request had insufficient authentication scopes.'}

我试图添加更多示波器(#)使用recretentials.json或token.json.json和non 。我是否需要更改我的凭据。我不知道这里的问题在哪里。 谢谢

I want to add my CSV file to my Google Drive sheet and I ended up with this script:

import gspread
import os.path
from google.oauth2.credentials import Credentials
from oauth2client.service_account import ServiceAccountCredentials

#scope = ['https://www.googleapis.com/auth/spreadsheets']
#scope = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/spreadsheets',
#         "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]


#scopes = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/spreadsheets',
#         "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]
scopes = ['https://www.googleapis.com/auth/spreadsheets']

if os.path.exists('token.json'):
        creds = Credentials.from_authorized_user_file('token.json', scopes) #credentials.json?
client = gspread.authorize(creds)

spreadsheet = client.open('Database-TTF')

with open('newTTF-Projects-INFO.csv', 'r') as file_obj:
    content = file_obj.read()
    client.import_csv('1gv-bKe-flo5FwIbt_xgCp1vNn0L0KBnpiuRak9a1efQ', data=content)

But unfortunately I got an error:

APIError: {'errors': [{'domain': 'global', 'reason': 'insufficientPermissions', 'message': 'Insufficient Permission: Request had insufficient authentication scopes.'}], 'code': 403, 'message': 'Insufficient Permission: Request had insufficient authentication scopes.'}

I was trying to add more scopes (#) use credentials.json or token.json and non of that worked. Do I need maybe to change something in my credentials.json file? I have no idea where is the problem here.
Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文