KeyError:'access_token'?

时间:2017-05-06 10:48:48

标签: python python-3.x access

当我尝试运行此代码时

from oauth2client.service_account import ServiceAccountCredentials
import requests, gspread
import os
import ast

def authenticate_google_docs():
    f = open(os.path.join('Checkin.p12'), 'rb')
    SIGNED_KEY = f.read()
    f.close()
    scope = ['https://spreadsheets.google.com/feeds', 'https://docs.google.com/feeds']
    credentials = ServiceAccountCredentials('danylo.lian@gmail.com', SIGNED_KEY, scope)

    data = {
        'refresh_token' : '<refresh-token-copied>',
        'client_id' : '<client-id-copied>',
        'client_secret' : '<client-secret-copied>',
        'grant_type' : 'refresh_token',
    }

    r = requests.post('https://accounts.google.com/o/oauth2/token', data = data)
    credentials.access_token = ast.literal_eval(r.text)['access_token']

    gc = gspread.authorize(credentials)
    return gc

gc = authenticate_google_docs()

sh = gc.open_by_url('https://docs.google.com/spreadsheets/d/11WR6rwQhL4wUDN8I77ju_5rzZl8IglsUjtUDI6pZsAQ/edit#gid=0')

我收到了错误

  

credentials.access_token = ast.literal_eval(r.text)['access_token']   KeyError:'access_token'

这意味着什么,我该怎么办?

0 个答案:

没有答案