I am trying to write a value to a cell with Google Sheet API with Java. For reading I used guide from Java Quickstart which worked fine for me.
For writing to Google
I was having the same issue. I resolved the problem that was in the scope. I just changed
SheetsScopes.SPREADSHEETS.READONLY
To
SheetsScopes.SPREADSHEETS
And it works very well.