0

I was trying to use oauth2client and gspread to operate on googlesheet but the problem i have is that when using oauth2client, it requires a field of scope. I have no idea what the scope is. The following is the code of the use of oauth2client.

import gspread
from oauth2client.service_account import ServiceAccountCredentials

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

credentials = ServiceAccountCredentials.from_json_keyfile_name('gspread-april-2cd … ba4.json', scope)

gc = gspread.authorize(credentials)

wks = gc.open("Where is the money Lebowski?").sheet1
Edccccch
  • 19
  • 1
  • 3
  • 8
  • Are you unable to open a spreadsheet? Or are you just wondering what the scope is? – Burnash Jul 17 '16 at 10:58
  • @Burnash I figured out the scope but I then used open_with_url and directly copied the url of my spreadsheet and it shows me 'no spreadsheet found' when I tried my code. The spreadsheet I created was from the same account I created the Google project(or API I forgot what It was called) – Edccccch Jul 18 '16 at 16:52
  • Did you share the spreadsheet with `client_email` in gspread-april-2cd...ba4.json – Burnash Jul 18 '16 at 18:20
  • 1
    That gspread-xxxx.json file is the one downloaded when I created the project right? And the client_email should be the Google account I created the project? – Edccccch Jul 18 '16 at 18:24
  • The best way is to follow the steps in http://gspread.readthedocs.io/en/latest/oauth2.html – Burnash Jul 18 '16 at 18:40
  • 1
    Yes, gspread-xxxx.json is the file you downloaded when you created credentials. `client_email` is a parameter *in this file*, and not the google account. – Burnash Jul 18 '16 at 18:42
  • That is awesome! Finally works! Thanks so much! – Edccccch Jul 18 '16 at 19:17

1 Answers1

0

The OAuth scopes express the permissions you request users to authorize for your app.

The one you used is the only available scope to authorize your request when using Google Sheets API v3.

https://spreadsheets.google.com/feeds

While if you used the Google Sheets API v4, you can now use either of these two scopes:

https://www.googleapis.com/auth/spreadsheets.readonly

that allows read-only access to the user's sheets and their properties and

https://www.googleapis.com/auth/spreadsheets

that allows read/write access to the user's sheets and their properties.

KENdi
  • 7,576
  • 2
  • 16
  • 31