将Telegram Bot连接到Google工作表

时间:2018-07-31 18:47:53

标签: python heroku oauth-2.0 google-sheets-api gspread

我在heroku中运行python脚本以将电报bot连接到Google工作表。我为此使用google sheet API,以将消息从漫游器保存到表单。每次我使用漫游器时,都会收到img中的错误消息。

gspread.exceptions.APIError: {
2018-07-31T10:37:11.672178+00:00 app[dana_bot.1]:   "error": {
2018-07-31T10:37:11.672179+00:00 app[dana_bot.1]:     "code": 401,
2018-07-31T10:37:11.672181+00:00 app[dana_bot.1]:     "message": 
"Request had invalid authentication credentials. Expected OAuth 2 access 
token, login cookie or other valid authentication credential. See 
https://developers.google.com/identity/sign-in/web/devconsole-project.",
2018-07-31T10:37:11.672183+00:00 app[dana_bot.1]:     "status": 
"UNAUTHENTICATED"
2018-07-31T10:37:11.672184+00:00 app[dana_bot.1]:   }
2018-07-31T10:37:11.672185+00:00 app[dana_bot.1]: }
2018-07-31T10:37:11.672186+00:00 app[dana_bot.1]: 

我尝试通过gspread使用OAuth 2.0客户端,但失败了吗?如果有人可以帮助我,我将很感激。

这是我用于身份验证的代码

import telebot
import gspread
import datetime
from oauth2client.service_account import ServiceAccountCredentials

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

creds = ServiceAccountCredentials.from_json_keyfile_name('DanaBot.json', 
scope)
client = gspread.authorize(creds)
sheet = client.open_by_url('https://docs.google.com/spreadsheets')

0 个答案:

没有答案