code: public static Credential getCredentialFromClientSecrets(String clientSecretsFile,
        String credentialId) {
      Preconditions.checkArgument(clientSecretsFile != null);
      Preconditions.checkArgument(credentialId != null);
  
      HttpTransport httpTransport;
      try {
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();
      } catch (IOException | GeneralSecurityException e) {
        throw new RuntimeException("Could not create HTTPS transport for use in credential creation", e);
      }
  
      JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
      GoogleClientSecrets clientSecrets;
  
      try {
        clientSecrets = GoogleClientSecrets.load(jsonFactory,
            new FileReader(clientSecretsFile));
      } catch (IOException e) {
        throw new RuntimeException(
            "Could not read the client secrets from file: " + clientSecretsFile,
            e);
      }
  
      FileDataStoreFactory dataStoreFactory;
      try {
        dataStoreFactory = new FileDataStoreFactory(CREDENTIAL_STORE);
      } catch (IOException e) {
        throw new RuntimeException("Could not create persisten credential store " + CREDENTIAL_STORE, e);
      }
  
      GoogleAuthorizationCodeFlow flow;
      try {
        flow = new GoogleAuthorizationCodeFlow.Builder(
            httpTransport, jsonFactory, clientSecrets, SCOPES)
            .setDataStoreFactory(dataStoreFactory)
            .build();
      } catch (IOException e) {
        throw new RuntimeException("Could not build credential authorization flow", e);
      }
  
      // The credentialId identifies the credential in the persistent credential store.
      Credential credential;
      try {
        credential = new AuthorizationCodeInstalledApp(flow, new PromptReceiver())
            .authorize(credentialId);
      } catch (IOException e) {
        throw new RuntimeException("Could not perform credential authorization flow", e);
      }
      return credential;
    }
docs: Creates an OAuth2 credential from client secrets, which may require an interactive authorization prompt.
  
  Use this method when the Application Default Credential is not sufficient.
  
  @param clientSecretsFile The {@code client_secrets.json} file path.
  @param credentialId The credentialId for use in identifying the credential in the persistent credential store.
  @return The user credential