-1

Is there any way to create spreadsheet only using the scope https://www.googleapis.com/auth/spreadsheets in Gspread?

Based on the documentation, seems like that scope itself can handle "create":

Google scope documentation

Please suggest the example code or web related to this issue

AngYC
  • 3,051
  • 6
  • 20

1 Answers1

1

Yes you can cretae a spreadsheet using Google API with just one of the following scopes:

  • https://www.googleapis.com/auth/drive
  • https://www.googleapis.com/auth/drive.file
  • https://www.googleapis.com/auth/spreadsheets

Source: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/create


The Google Drive permission scope is only required if you intent to save the file to a specific folder. Otherwise, you can save to root directly with just the https://www.googleapis.com/auth/spreadsheets scope.

Although it is possible to pass in custom scopes in GSpread:

# Use one of the following, depends on your use case
gspread.oauth(scopes=['https://www.googleapis.com/auth/drive'])
gspread.service_account(scopes=['https://www.googleapis.com/auth/drive'])

Source: https://docs.gspread.org/en/latest/api/top-level.html


However, in the source code: https://github.com/burnash/gspread/blob/50b910f2911c6203e139934bafbbce9fe300e8e1/gspread/client.py#L228

It used the Google Drive's create API to create the Spreadsheet instead of using Google Sheets API, that's why it will require the https://www.googleapis.com/auth/drive scope

AngYC
  • 3,051
  • 6
  • 20
  • I got this error that why i am asking: gspread.exceptions.APIError: {'code': 403, 'message': 'Request had insufficient authentication scopes.', 'errors': [{'message': 'Insufficient Permission', 'domain': 'global', 'reason': 'insufficientPermissions'}], 'status': 'PERMISSION_DENIED', 'details': [{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'ACCESS_TOKEN_SCOPE_INSUFFICIENT', 'domain': 'googleapis.com', 'metadata': {'method': 'google.apps.drive.v3.DriveFiles.Create', 'service': 'drive.googleapis.com'}}]}This error coming from gs = gspread.authorize(cred); sh = gs.create(name) – Renardi Adryantoro Priambudi May 01 '23 at 05:09
  • Hi @RenardiAdryantoroPriambudi, unfortunately this is an issue in GSpread code, refer to my edited answer above. – AngYC May 01 '23 at 05:15