Skip to content

Please update the quickstart guide with an example using google-auth-library-java #7388

Open

Description

@SEOguruNL

Problem
The example in the quickstart guide 'Running a Search Console App in Java' is still using the deprecated googleapis.auth.oauth2.GoogleCredential. I understand that googleapis.google-auth-library-java.credentials should be used instead.

Solution
I'd like to see an updated example in the quickstart-guide where the google-auth-library-java is used.

Additional context
I've asked this question on several places, but nobody seems to be able to come up with an example.

Activity

  1. added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    and removed
    triage meI really want to be triaged.
    on Mar 25, 2021
  2. haimraman commented on Mar 29, 2021

    @haimraman

    I was missing this documentation as well, what I was able to figurer out from the project README
    https://github.com/googleapis/google-auth-library-java#google-auth-library-credentials was this.
    Credentials were generated as a service account from https://console.cloud.google.com/
    with Enable G Suite domain-wide delegation

      final var accountCredentials = ServiceAccountCredentials.fromStream(new FileInputStream(
                    "custom-octagon-abc1234.json"));
            ServiceAccountCredentials serviceAccountCredentials = ServiceAccountCredentials.newBuilder()
                    .setClientId(accountCredentials.getClientId())
                    .setClientEmail(accountCredentials.getClientEmail())
                    .setPrivateKey(accountCredentials.getPrivateKey())
                    .setPrivateKeyId(accountCredentials.getPrivateKeyId())
                    .setScopes(SCOPES)
                    .setServiceAccountUser("delegated-user@domain.what.ever")
                    .setProjectId(accountCredentials.getProjectId())
                    .build();
    
            HttpCredentialsAdapter credentialsAdapter = new HttpCredentialsAdapter(serviceAccountCredentials);
            Gmail service = new Gmail.Builder(GoogleNetHttpTransport.newTrustedTransport(),
                    GsonFactory.getDefaultInstance(),
                    credentialsAdapter).setApplicationName("My App").build();
    
            String user = "me";
            final var messagesResponse = service.users().labels().list(user).execute();
            System.out.println(messagesResponse.getLabels().stream().map(Label::getName).collect(Collectors.joining(",\n"))); 
    

    Although it works for me I sill missing official examples and a bit lost between all the token types and when should I use IAM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p4type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions