Google API Python Script凭据错误
我想将我的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论