inferno
inferno

Reputation: 45

python gspread authorize oauth2 credentials

How can i make gspread use my oauth credentials? I having error for http response gspread.httpsession.HTTPError :( can anyone tell me what's wrong with my code?

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')

Where row contains data from database (It has access token returned by google oauth)? m(_ _)m

Upvotes: 1

Views: 2079

Answers (1)

jdk514
jdk514

Reputation: 106

I was having complications with authenticating using Oauth2Credentials too. My suggestion is use googles Oauth2 workflow to create the credentials. In addition make sure you use 'https://spreadsheets.google.com/feeds' as the scope of the credentials.

I am currently using this process and my calls work fine.

Upvotes: 1

Related Questions