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?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With