无法使用gspread.service_account()进行身份验证

时间:2020-11-06 03:59:21

标签: python-3.x google-sheets-api gspread

我正在创建一个脚本,使用python库gspread将CSV文件上传到Google电子表格。我无法使用gspread的.service_account()身份验证向gspread进行身份验证来请求我的电子表格。任何帮助将不胜感激。我的代码在下面。

import gspread

#UPLOAD CSV START

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"]

print("some text here to see if the code up to this point is running")

client = gspread.service_account(filename="you google sheets credentials .json here")


print("some text here to see if the code up to this point is running")
spreadsheet = client.open('Products')


print("some text here to see if the code up to this point is running")

with open('data.csv', 'r') as file_obj:
    content = file_obj.read()
    client.import_csv(spreadsheet.id, data=content)
print("some text here to see if the code up to this point is running")
#UPLOAD CSV END

非常感谢您的帮助

0 个答案:

没有答案