我对Python比较陌生,所以请原谅我的愚蠢。我想检查谷歌表数据并在扫描错误时继续运行到EOL。我看了其他帖子并尝试了各种策略,但似乎都没有结果。我认为客户端电子邮件或私人ID似乎是引号的问题。
import gspread
from oauth2client.service_account import *
json_key = 'gspread-test.json'
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('test@developer.gserviceaccount.com', """
-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDVS4fuXzpnKrAI\nfaZEhkNdkcHKwcbQdYOhsxVwiaMkTffExvix+Uch37JaTIyCCw4D0CKv5bR\n5FOQPAVJgciJTUKK03UZJZfgtNWVY73dBq5DTL0afI2tn9+sKgtm/BulgA\nPrKtDmlp5YX7atgXbwJTjWpZ8OLOdBtwAcL0zBYS2PR/+qNOPT1NP1tJgTEMHmbN\nuyEl0Xqqrm87Ku7eaMEcmlQrhGLH2WmpR0YEXs2hQLGx\ne/RbqrD3qr/XYbRm9TwZkCyt\n-----END PRIVATE KEY-----\n
""", scope)
gc = gspread.authorize(credentials)
wks = gc.open('Simple data').sheet1
答案 0 :(得分:0)
ServiceAccountCredentials.from_json_keyfile_name()函数有2个参数:
这样的事情应该有效:
path_to_json = <<absolute path to json file>>
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name(path_to_json, scope)
client = gspread.authorize(credentials)
然后client
可用于访问您想要的任何工作表。