Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
coolrb opened this issue Mar 19, 2023 · 0 comments
Assignees

Comments

@coolrb
Copy link

coolrb commented Mar 19, 2023

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants