Failing to access G Suite Admin SDK API's

I am trying to access G Suite Admin SDK API’s, but failing to access

using below snippet :

public static  Set<String> getUsersList(InputStream serviceKeyStream)
      throws IOException, GeneralSecurityException {

    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();

    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    GoogleCredential credential =
        GoogleCredential.fromStream(serviceKeyStream).createScoped(ADMIN_SCOPES);

    Credential adminCredential =
        new GoogleCredential.Builder()
            .setTransport(httpTransport)
            .setJsonFactory(jsonFactory)
            .setServiceAccountId(credential.getServiceAccountId())
            .setServiceAccountPrivateKey(credential.getServiceAccountPrivateKey())
            .setServiceAccountScopes(ADMIN_SCOPES)
            .build();

    var directory = new Directory.Builder(
            httpTransport,
            jsonFactory,
            request -> {
              adminCredential.initialize(request);
            })
        .build();

    Set<String> allUserIds = new HashSet<>();
    String nextPageToken = null;
    do {
      Users users =
          directory
              .users()
              .list()
              .setMaxResults(NUM_USERS_PER_PAGE)
              .setDomain("***")
              .setViewType("domain_public")
              .setCustomer("my_customer")
              .setPageToken(nextPageToken)
              .execute();
      List<User> userList = users.getUsers();
      if (userList != null) {
        allUserIds.addAll(userList.stream().map(User::getPrimaryEmail).collect(Collectors.toSet()));
      }
      nextPageToken = users.getNextPageToken();
    } while (nextPageToken != null);
     return  allUserIds;
  }

Getting response as :

403 Forbidden

{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "Not Authorized to access this resource/api",
    "reason" : "forbidden"
  } ],
  "message" : "Not Authorized to access this resource/api"
}

Hey there,

nice to meet you! :wave:

So the authorization fails.
How did you add it?
Some sort of an API key?