Issue
I'm getting this error when Im trying to write data to my spreadsheet in Google sheets.
{"code": 403,"details": [{"@type": "type.googleapis.com/google.rpc.ErrorInfo","reason": "ACCESS_TOKEN_SCOPE_INSUFFICIENT"}],"errors": [{"domain": "global","message": "Insufficient Permission","reason": "insufficientPermissions"}],"message": "Request had insufficient authentication scopes.","status": "PERMISSION_DENIED"}
The Java code:
public static void updateData(String sheetName, String cellLocation, String newValue) throws Exception {
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
Sheets service = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
.setApplicationName(APPLICATION_NAME)
.build();
ValueRange body = new ValueRange()
.setValues(Arrays.asList(Arrays.asList(newValue)));
UpdateValuesResponse result =
service.spreadsheets().values().update(spreadsheetId, cellLocation, body)
.setValueInputOption("RAW")
.execute();
System.out.printf("%d cells updated.", result.getUpdatedCells());
}
Thank You!
I have tried to make my spreadsheet public.
Solution
Your program uses spreadsheets().values().update() which requires OAuth scopes.
This is the reason why the "Request had insufficient authentication scopes" error occurs. Refer to https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update?hl=en for more details.
This link should help you in authorizing the application. https://developers.google.com/sheets/api/quickstart/java?hl=en
Answered By - Jerrymon
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.