use of com.google.api.ads.common.lib.auth.GoogleClientSecretsBuilder in project googleads-java-lib by googleads.
the class GetRefreshToken method main.
public static void main(String[] args) throws Exception {
// Get the client ID and secret from the ads.properties file.
// If you do not have a client ID or secret, please create one in the
// API console: https://console.developers.google.com/project and set it
// in the ads.properties file.
GoogleClientSecrets clientSecrets = null;
try {
clientSecrets = new GoogleClientSecretsBuilder().forApi(Api.AD_MANAGER).fromFile().build();
} catch (ValidationException e) {
System.err.println("Please input your client ID and secret into your ads.properties file, which is either " + "located in your home directory in your src/main/resources directory, or " + "on your classpath. If you do not have a client ID or secret, please create one in " + "the API console: https://console.developers.google.com/project");
System.exit(1);
}
// Get the OAuth2 credential.
Credential credential = getOAuth2Credential(clientSecrets);
System.out.printf("Your refresh token is: %s%n", credential.getRefreshToken());
// Enter the refresh token into your ads.properties file.
System.out.printf("In your ads.properties file, modify:%n%napi.admanager.refreshToken=%s%n", credential.getRefreshToken());
}
use of com.google.api.ads.common.lib.auth.GoogleClientSecretsBuilder in project googleads-java-lib by googleads.
the class GetRefreshTokenWithoutPropertiesFile method main.
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, UTF_8));
System.out.println("Please input your client ID and secret. " + "If you do not have a client ID or secret, please create one in " + "the API console: https://console.developers.google.com");
System.out.println("Enter your client ID: ");
String clientId = reader.readLine();
if (Strings.isNullOrEmpty(clientId)) {
System.err.println("Please input your client ID.");
System.exit(1);
}
System.out.println("Enter your client secret: ");
String clientSecret = reader.readLine();
if (Strings.isNullOrEmpty(clientSecret)) {
System.err.println("Please input your client secret.");
System.exit(1);
}
GoogleClientSecrets clientSecrets = null;
try {
clientSecrets = new GoogleClientSecretsBuilder().forApi(Api.AD_MANAGER).withClientSecrets(clientId, clientSecret).build();
} catch (ValidationException e) {
System.err.println("Please input your client ID and secret. If you do not have a " + "client ID or secret, please create one in " + "the API console: https://console.developers.google.com");
System.exit(1);
}
// Get the OAuth2 credential.
Credential credential = getOAuth2Credential(clientSecrets);
System.out.printf("Your refresh token is: %s%n", credential.getRefreshToken());
}
use of com.google.api.ads.common.lib.auth.GoogleClientSecretsBuilder in project googleads-java-lib by googleads.
the class GetRefreshToken method main.
public static void main(String[] args) {
// Get the client ID and secret from the ads.properties file.
// If you do not have a client ID or secret, please create one in the
// API console: https://console.developers.google.com/project and set it
// in the ads.properties file.
GoogleClientSecrets clientSecrets = null;
try {
clientSecrets = new GoogleClientSecretsBuilder().forApi(Api.ADWORDS).fromFile().build();
} catch (ValidationException e) {
System.err.println("Please input your client ID and secret into your ads.properties file, which is either " + "located in your home directory, in your src/main/resources directory, or " + "on your classpath. If you do not have a client ID or secret, please create one in " + "the API console: https://console.developers.google.com/project");
return;
} catch (ConfigurationLoadException cle) {
System.err.printf("Failed to load configuration from the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, cle);
return;
}
// Get the OAuth2 credential.
Credential credential = null;
try {
credential = getOAuth2Credential(clientSecrets);
} catch (IOException ioe) {
System.err.printf("Failed to generate credentials. Exception: %s%n", ioe);
return;
}
System.out.printf("Your refresh token is: %s%n", credential.getRefreshToken());
// Enter the refresh token into your ads.properties file.
System.out.printf("In your ads.properties file, modify:%n%napi.adwords.refreshToken=%s%n", credential.getRefreshToken());
}
use of com.google.api.ads.common.lib.auth.GoogleClientSecretsBuilder in project googleads-java-lib by googleads.
the class GetRefreshTokenWithoutPropertiesFile method main.
public static void main(String[] args) {
String clientId;
String clientSecret;
// Reading from stdin, so default charset is appropriate.
@SuppressWarnings("DefaultCharset") BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please input your client ID and secret. " + "If you do not have a client ID or secret, please create one in " + "the API console: https://console.developers.google.com");
try {
System.out.println("Enter your client ID: ");
clientId = reader.readLine();
if (Strings.isNullOrEmpty(clientId)) {
System.err.println("Invalid client ID.");
return;
}
System.out.println("Enter your client secret: ");
clientSecret = reader.readLine();
if (Strings.isNullOrEmpty(clientSecret)) {
System.err.println("Invalid client secret.");
return;
}
} catch (IOException ioe) {
System.err.printf("Failed to read client ID and secret: %s%n", ioe);
return;
}
GoogleClientSecrets clientSecrets = null;
try {
clientSecrets = new GoogleClientSecretsBuilder().forApi(Api.ADWORDS).withClientSecrets(clientId, clientSecret).build();
} catch (ValidationException e) {
System.err.println("Please input your client ID and secret. If you do not have a " + "client ID or secret, please create one in " + "the API console: https://console.developers.google.com");
return;
}
// Get the OAuth2 credential.
Credential credential = null;
try {
credential = getOAuth2Credential(clientSecrets);
} catch (IOException ioe) {
System.err.printf("Failed to generate credentials. Exception: %s%n", ioe);
return;
}
System.out.printf("Your refresh token is: %s%n", credential.getRefreshToken());
}
Aggregations