Skip to content

Deleting a message gives GoogleJsonResponseException: Request had insufficient authentication scopes. #631

Open
@coolrb

Description

@coolrb

Summary

I am trying to delete a message using
gmail.users().messages().delete("me", msgId).execute();
But it gives exception. However sending the message works.

GoogleJsonResponseException: Request had insufficient authentication scopes.

private Credential authorize(final NetHttpTransport HTTP_TRANSPORT)
throws IOException {

    Path file = ResourceUtils.getFile(credentialFilePath).toPath();
    log.info(file.toUri().getPath());
    InputStream in = new FileInputStream(file.toFile());

    GoogleClientSecrets clientSecrets =
            GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

    List<String> scopes = new ArrayList<>();
    scopes.add(GmailScopes.GMAIL_MODIFY);


    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes)
            .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(tokenDirectoryPath)))
            .setAccessType("offline")
            .build();
    LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
    Credential credential = new AuthorizationCodeInstalledApp(flow, receiver).authorize(email);
    
    return credential;
}

Gmail Quickstart - Delete message

Message should get deleted

Generates exception

Specifications

  • openjdk 17.0.6 2023-01-17
  • Mac

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions