2014-10-02 127 views
1

我該如何讓gspread使用我的oauth憑證?我具有HTTP響應gspread.httpsession.HTTPError錯誤:( 誰能告訴我什麼是錯我的代碼?python gspread授權oauth2憑證

import datetime 
import gspread 
import json 
import MySQLdb 
from oauth2client.client import OAuth2Credentials 


# Get access token from database 
data = json.loads(row['access_token']) 
credentials = OAuth2Credentials(
    data['access_token'], 
    "1*************************k.apps.googleusercontent.com", 
    "9t*****************W", 
    data['refresh_token'], 
    datetime.datetime.now(), 
    "https://accounts.google.com/o/oauth2/token", 
    'user-agent' 
) 

gc = gspread.authorize(credentials) 
wks = gc.open_by_key('1*****************W') 

當行包含從數據庫中的數據(它由谷歌返回的OAuth訪問令牌)?M( _ _)M

回答

1

我是有使用Oauth2Credentials過驗證的併發症。我的建議是使用googles的oauth2工作流程創建憑據。另外一定要使用「https://spreadsheets.google.com/feeds」作爲憑證的範圍。

我目前正在使用這個過程和我的ca我的工作很好。