Google API (Sheets) API Error code 403. Insufficient Permission: Request had insufficient authentication scopes

11,076

Solution 1

Authentication scopes allow your application to perform certain actions on the service using OAuth2 authentication. When using google APIs, please refer to the Google API scopes sheet.

See the Google Sheets API V4 related scopes in the below image.Please make sure not to give extra permissions which could affect the security of your application.

enter image description here

Please Note: Since you are planning on changing the scopes, first delete the token.json file created in the local project folder, and then allow access to your application again. This will create a new token.json file.

Solution 2

i saw a new way on github using a google lib. Doing this

import gspread
from google.oauth2.service_account import Credentials

scope = ['https://spreadsheets.google.com/feeds',
         'https://www.googleapis.com/auth/drive']

creds = Credentials.from_service_account_file('client_secret.json', scopes=scope)

client = gspread.authorize(creds) 

i used this link: https://github.com/burnash/gspread

Share:
11,076
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I am trying out a project where I am able to use python (im using jupyter notebooks on Anaconda) to read data from google sheets. I watched a few videos and guides and replicated the code. However, I am unable to get the code to work correctly

    import pandas as pd
    import gspread
    from oauth2client.service_account import ServiceAccountCredentials
    scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
    creds = ServiceAccountCredentials.from_json_keyfile_name('test.json',scope)
    client = gspread.authorize(creds)
    data = gc.open('TEST').sheet1
    print(data.get_all_records())
    

    The error message I got was

    APIError: {
     "error": {
      "errors": [
       {
        "domain": "global",
        "reason": "insufficientPermissions",
        "message": "Insufficient Permission: Request had insufficient authentication scopes."
       }
      ],
      "code": 403,
      "message": "Insufficient Permission: Request had insufficient authentication scopes."
     }
    }
    

    Any advice on what I should do?