Search in sources :

Example 1 with DataStoreFactory

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);
}
Also used : MemoryDataStoreFactory(com.google.api.client.util.store.MemoryDataStoreFactory) AdManagerSession(com.google.api.ads.admanager.lib.client.AdManagerSession) MemoryDataStoreFactory(com.google.api.client.util.store.MemoryDataStoreFactory) DataStoreFactory(com.google.api.client.util.store.DataStoreFactory) AdManagerServices(com.google.api.ads.admanager.axis.factory.AdManagerServices)

Example 2 with DataStoreFactory

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);
    }
}
Also used : MemoryDataStoreFactory(com.google.api.client.util.store.MemoryDataStoreFactory) ValidationException(com.google.api.ads.common.lib.exception.ValidationException) AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) AdWordsServicesInterface(com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface) ReportException(com.google.api.ads.adwords.lib.utils.ReportException) IOException(java.io.IOException) DetailedReportDownloadResponseException(com.google.api.ads.adwords.lib.utils.DetailedReportDownloadResponseException) ReportDownloadResponseException(com.google.api.ads.adwords.lib.utils.ReportDownloadResponseException) DetailedReportDownloadResponseException(com.google.api.ads.adwords.lib.utils.DetailedReportDownloadResponseException) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) IOException(java.io.IOException) ReportDownloadResponseException(com.google.api.ads.adwords.lib.utils.ReportDownloadResponseException) ValidationException(com.google.api.ads.common.lib.exception.ValidationException) ReportException(com.google.api.ads.adwords.lib.utils.ReportException) DataStoreFactory(com.google.api.client.util.store.DataStoreFactory) MemoryDataStoreFactory(com.google.api.client.util.store.MemoryDataStoreFactory)

Aggregations

DataStoreFactory (com.google.api.client.util.store.DataStoreFactory)2 MemoryDataStoreFactory (com.google.api.client.util.store.MemoryDataStoreFactory)2 AdManagerServices (com.google.api.ads.admanager.axis.factory.AdManagerServices)1 AdManagerSession (com.google.api.ads.admanager.lib.client.AdManagerSession)1 AdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession)1 AdWordsServicesInterface (com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface)1 DetailedReportDownloadResponseException (com.google.api.ads.adwords.lib.utils.DetailedReportDownloadResponseException)1 ReportDownloadResponseException (com.google.api.ads.adwords.lib.utils.ReportDownloadResponseException)1 ReportException (com.google.api.ads.adwords.lib.utils.ReportException)1 ConfigurationLoadException (com.google.api.ads.common.lib.conf.ConfigurationLoadException)1 ValidationException (com.google.api.ads.common.lib.exception.ValidationException)1 IOException (java.io.IOException)1