Home > Mobile >  Permissions - Google Sheets API
Permissions - Google Sheets API

Time:03-24

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.

CodePudding user response:

Your program uses spreadsheets().values().update() which requires OAuth scopes. enter image description here

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

  • Related