I'm currently trying to make updates to google sheets via python and I'm running into some issues with permissions.
I've been following the instructions from this Twilio guide:https://www.twilio.com/blog/2017/02/an-easy-way-to-read-and-write-to-a-google-spreadsheet-in-python.html
I'm doing all of this in Jupyter, and I did save the JSON file to the proper code directory. I had no problems defining scope, creds and client.
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_id.json', scope)
client = gspread.authorize(creds)
sheet = client.open("MixIQ Tracker").sheet1
I've followed all of the steps to link the two, but I am getting this API Error with the last line.
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."
}
}
I'm not exactly sure how to resolve this. Any direction would be greatly appreciated!
Search for 'Google Drive API', enable it. Select Compute Engine service default, JSON, hit create. Open up the JSON file, share your spreadsheet with the "[email protected]" email listed. Save the JSON file wherever you're hosting your project, you'll need to load it in through Python later.
Its Data Analysis libraries, such as Pandas and NumPy, are mostly used to manipulate and analyze data effectively. And hence, a Python to Google Sheets connect leverages NumPy or Pandas to integrate the data.
I believe google drive API endpoint needs to be included in your scope. I was writing data from Mailchimp API to Google Sheet.
Check this out: https://www.youtube.com/watch?v=7I2s81TsCnc> It was helpful for me.
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
If you look at the google API scopes documentation, the scope url you are using is not referenced anywhere. This may be the problem. Try changing the scope url to https://www.googleapis.com/auth/spreadsheets
.
Also, make sure the spreadsheet API is correctly enabled in your project in the google developer console.
Alternatively, you could try the Sheetfu library (I'm the author), that handles the scopes for you.
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