use of com.google.api.client.util.store.DataStoreFactory in project googleads-java-lib by googleads.
the class AdvancedCreateCredentialFromScratch method main.
public static void main(String[] args) throws Exception {
if (CLIENT_ID.equals("INSERT_CLIENT_ID_HERE") || CLIENT_SECRET.equals("INSERT_CLIENT_SECRET_HERE")) {
throw new IllegalArgumentException("Please input your client IDs or secret. " + "See https://console.developers.google.com/project");
}
// It is highly recommended that you use a credential store in your
// application to store a per-user Credential.
// See:
// https://developers.google.com/api-client-library/java/google-api-java-client/oauth2#data_store
DataStoreFactory storeFactory = new MemoryDataStoreFactory();
// Authorize and store your credential.
authorize(storeFactory, USER_ID);
// Create a AdManagerSession from the credential store. You will typically do this
// in a servlet interceptor for a web application or per separate thread
// of your offline application.
AdManagerSession adManagerSession = createDfpSession(storeFactory, USER_ID);
AdManagerServices adManagerServices = new AdManagerServices();
runExample(adManagerServices, adManagerSession);
}
use of com.google.api.client.util.store.DataStoreFactory in project googleads-java-lib by googleads.
the class AdvancedCreateCredentialFromScratch method main.
public static void main(String[] args) {
if (CLIENT_ID.equals("INSERT_CLIENT_ID_HERE") || CLIENT_SECRET.equals("INSERT_CLIENT_SECRET_HERE")) {
throw new IllegalArgumentException("Please input your client IDs or secret. " + "See https://console.developers.google.com/project");
}
// It is highly recommended that you use a credential store in your
// application to store a per-user Credential.
// See: https://developers.google.com/api-client-library/java/google-api-java-client/oauth2#data_store
DataStoreFactory storeFactory = new MemoryDataStoreFactory();
// Authorize and store your credential.
try {
authorize(storeFactory, USER_ID);
} catch (Exception e) {
System.err.printf("Failed to authorize credentials: %s%n", e);
return;
}
// Create a AdWordsSession from the credential store. You will typically do this
// in a servlet interceptor for a web application or per separate thread
// of your offline application.
AdWordsSession adWordsSession;
try {
adWordsSession = createAdWordsSession(USER_ID, storeFactory);
} catch (ConfigurationLoadException cle) {
System.err.printf("Failed to load configuration from the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, cle);
return;
} catch (ValidationException ve) {
System.err.printf("Invalid configuration in the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, ve);
return;
} catch (IOException ioe) {
System.err.printf("Failed to load OAuth credentials from local data store. Exception: %s%n", ioe);
return;
}
AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();
// Location to download report to.
String reportFile = System.getProperty("user.home") + File.separatorChar + "report.csv";
try {
runExample(adWordsServices, adWordsSession, reportFile);
} catch (ReportDownloadResponseException rde) {
// A ReportDownloadResponseException will be thrown if the HTTP status code in the response
// indicates an error occurred, but the response did not contain further details.
System.err.printf("Report was not downloaded due to: %s%n", rde);
} catch (ReportException re) {
// A ReportException will be thrown if the download failed due to a transport layer exception.
System.err.printf("Report was not downloaded due to transport layer exception: %s%n", re);
} catch (IOException ioe) {
// An IOException in this example indicates that the report's contents could not be read from
// the response.
System.err.printf("Report was not read due to an IOException: %s%n", ioe);
}
}
Aggregations