Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 1.41 KB

oauth2.rst

File metadata and controls

43 lines (30 loc) · 1.41 KB

Using OAuth2 for Authorization

OAuth Credentials

OAuth credentials can be generated in several different ways using the oauth2client library provided by Google. If you are editing spreadsheets for yourself then the easiest way to generate credentials is to use Signed Credentials stored in your application (see example below). If you plan to edit spreadsheets on behalf of others then visit the Google OAuth2 documentation for more information.

Using Signed Credentials

import gspread
from oauth2client.client import SignedJwtAssertionCredentials

scope = ['https://spreadsheets.google.com/feeds', 'https://docs.google.com/feeds']

credentials = SignedJwtAssertionCredentials('developer@example.com', SIGNED_KEY, scope)

gc = gspread.authorize(credentials)
wks = gc.open("Where is the money Lebowski?").sheet1

Custom Credentials Objects

If you have another method of authenicating you can easily hack a custom credentials object.

class Credentials (object):
  def __init__ (self, access_token=None):
    self.access_token = access_token

  def refresh (self, http):
    # get new access_token
    # this only gets called if access_token is None