com.google.api.ads.common.lib.auth.OfflineCredentials.Api Java Examples

The following examples show how to use com.google.api.ads.common.lib.auth.OfflineCredentials.Api. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OfflineCredentialsTest.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the builder correctly reads from a file.
 */
@Test
public void testReadPropertiesFromFile() throws Exception {
  PropertiesConfiguration config = new PropertiesConfiguration();
  config.setProperty("api.admanager.clientId", "clientId");
  config.setProperty("api.admanager.clientSecret", "clientSecret");
  config.setProperty("api.admanager.refreshToken", "refreshToken");

  when(configurationHelper.fromFile("path")).thenReturn(config);

  ForApiBuilder builder = new OfflineCredentials.ForApiBuilder(
      configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper);

  OfflineCredentials offlineCredentials = builder.fromFile("path").build();

  assertEquals("clientId", offlineCredentials.getClientId());
  assertEquals("clientSecret", offlineCredentials.getClientSecret());
  assertEquals("refreshToken", offlineCredentials.getRefreshToken());
}
 
Example #2
Source File: OfflineCredentialsTest.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the builder correctly reads properties from a configuration.
 */
@Test
public void testReadPropertiesFromConfiguration_properPrefix() throws ValidationException {
  PropertiesConfiguration config = new PropertiesConfiguration();
  config.setProperty("api.admanager.clientId", "clientIdDfp");
  config.setProperty("api.admanager.clientSecret", "clientSecretDfp");
  config.setProperty("api.admanager.refreshToken", "refreshTokenDfp");
  config.setProperty("api.adwords.clientId", "clientIdAdWords");
  config.setProperty("api.adwords.clientSecret", "clientSecretAdWords");
  config.setProperty("api.adwords.refreshToken", "refreshTokenAdWords");

  OfflineCredentials offlineCredentials = new OfflineCredentials.Builder()
      .forApi(OfflineCredentials.Api.AD_MANAGER)
      .from(config)
      .build();

  assertEquals("clientIdDfp", offlineCredentials.getClientId());
  assertEquals("clientSecretDfp", offlineCredentials.getClientSecret());
  assertEquals("refreshTokenDfp", offlineCredentials.getRefreshToken());
}
 
Example #3
Source File: OfflineCredentialsTest.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the builder correctly identifies the file path.
 */
@Test
public void testReadPropertiesFromFile_clientSecretTokenBadWithFilePath() throws Exception {
  PropertiesConfiguration config = new PropertiesConfiguration();
  config.setProperty("api.admanager.clientId", "clientId");
  config.setProperty("api.admanager.refreshToken", "refreshToken");

  when(configurationHelper.fromFile("/home/user/path")).thenReturn(config);

  ForApiBuilder builder = new OfflineCredentials.ForApiBuilder(
      configurationHelper, OfflineCredentials.Api.AD_MANAGER, oAuth2Helper);

  thrown.expect(ValidationException.class);
  thrown.expectMessage(
      "Client secret must be set as api.admanager.clientSecret in /home/user/path."
          + "\nIf you do not have a client ID or secret, please create one in the API "
          + "console: https://console.developers.google.com/project");
  builder.fromFile("/home/user/path").build();
}
 
Example #4
Source File: OfflineCredentialsTest.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the builder does not fail when missing everything but a service account key and
 * service account user.
 */
@Test
public void testReadPropertiesFromConfiguration_onlyKeyFilePathAndUser() throws Exception {
  PropertiesConfiguration config = new PropertiesConfiguration();
  config.setProperty("api.admanager.jsonKeyFilePath", "jsonKeyFilePath");
  config.setProperty("api.admanager.serviceAccountUser", "[email protected]");

  OfflineCredentials credentials = new Builder().forApi(Api.AD_MANAGER).from(config).build();
  assertEquals(
      "service account user should have been set from the config",
      "[email protected]",
      credentials.getServiceAccountUser());
}
 
Example #5
Source File: GetAllAdUnitSizes.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  try {
    runExample(adManagerServices, session);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #6
Source File: GetCustomFieldsForLineItems.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  try {
    runExample(adManagerServices, session);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #7
Source File: CreateCreativesFromTemplates.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  CreateCreativesFromTemplatesParams params = new CreateCreativesFromTemplatesParams();
  if (!params.parseArguments(args)) {
    // Either pass the required parameters for this example on the command line, or insert them
    // into the code here. See the parameter class definition above for descriptions.
    params.advertiserId = Long.parseLong("INSERT_ADVERTISER_ID_HERE");
  }

  try {
    runExample(adManagerServices, session, params.advertiserId);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  } catch (IOException ioe) {
    System.err.printf("Example failed due to IOException: %s%n", ioe);
  }
}
 
Example #8
Source File: GetLicasForLineItem.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  GetLicasForLineItemParams params = new GetLicasForLineItemParams();
  if (!params.parseArguments(args)) {
    // Either pass the required parameters for this example on the command line, or insert them
    // into the code here. See the parameter class definition above for descriptions.
    params.lineItemId = Long.parseLong("INSERT_LINE_ITEM_ID_HERE");
  }

  try {
    runExample(adManagerServices, session, params.lineItemId);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #9
Source File: GetAccountHierarchy.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdWordsSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.ADWORDS)
            .fromFile()
            .build()
            .generateCredential();

    // Construct an AdWordsSession.
    session =
        new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();

  try {
    runExample(adWordsServices, session);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the adwords.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf(
        "Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #10
Source File: CreateTeams.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  try {
    runExample(adManagerServices, session);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #11
Source File: MakeTestNetwork.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  try {
    runExample(adManagerServices, session);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #12
Source File: GetAllContacts.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  try {
    runExample(adManagerServices, session);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #13
Source File: CreateCreativesFromTemplates.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  CreateCreativesFromTemplatesParams params = new CreateCreativesFromTemplatesParams();
  if (!params.parseArguments(args)) {
    // Either pass the required parameters for this example on the command line, or insert them
    // into the code here. See the parameter class definition above for descriptions.
    params.advertiserId = Long.parseLong("INSERT_ADVERTISER_ID_HERE");
  }

  try {
    runExample(adManagerServices, session, params.advertiserId);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  } catch (IOException ioe) {
    System.err.printf("Example failed due to IOException: %s%n", ioe);
  }
}
 
Example #14
Source File: GetActiveActivities.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  try {
    runExample(adManagerServices, session);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #15
Source File: CreateUsers.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  CreateUsersParams params = new CreateUsersParams();
  if (!params.parseArguments(args)) {
    // Either pass the required parameters for this example on the command line, or insert them
    // into the code here. See the parameter class definition above for descriptions.
    params.emailAddress = "INSERT_EMAIL_ADDRESS_HERE";
    params.name = "INSERT_NAME_HERE";
  }

  try {
    runExample(adManagerServices, session, params.emailAddress, params.name);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #16
Source File: FindAndRemoveCriteriaFromSharedSet.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdWordsSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.ADWORDS)
            .fromFile()
            .build()
            .generateCredential();

    // Construct an AdWordsSession.
    session =
        new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();

  FindAndRemoveCriteriaFromSharedSetParams params =
      new FindAndRemoveCriteriaFromSharedSetParams();
  if (!params.parseArguments(args)) {
    // Either pass the required parameters for this example on the command line, or insert them
    // into the code here. See the parameter class definition above for descriptions.
    params.campaignId = Long.parseLong("INSERT_CAMPAIGN_ID_HERE");
  }

  try {
    runExample(adWordsServices, session, params.campaignId);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the adwords.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf(
        "Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #17
Source File: UpdatePlacements.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  UpdatePlacementsParams params = new UpdatePlacementsParams();
  if (!params.parseArguments(args)) {
    // Either pass the required parameters for this example on the command line, or insert them
    // into the code here. See the parameter class definition above for descriptions.
    params.placementId = Long.parseLong("INSERT_PLACEMENT_ID_HERE");
  }

  try {
    runExample(adManagerServices, session, params.placementId);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #18
Source File: GetAllPlacements.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  try {
    runExample(adManagerServices, session);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #19
Source File: DeactivateCreativeWrappersForLabel.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  DeactivateCreativeWrappersForLabelParams params =
      new DeactivateCreativeWrappersForLabelParams();
  if (!params.parseArguments(args)) {
    // Either pass the required parameters for this example on the command line, or insert them
    // into the code here. See the parameter class definition above for descriptions.
    params.labelId = Long.parseLong("INSERT_LABEL_ID_HERE");
  }

  try {
    runExample(adManagerServices, session, params.labelId);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #20
Source File: GetLineItemsThatNeedCreatives.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  try {
    runExample(adManagerServices, session);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #21
Source File: CreateCustomTargetingKeysAndValues.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  try {
    runExample(adManagerServices, session);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #22
Source File: GetUninvitedContacts.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  try {
    runExample(adManagerServices, session);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #23
Source File: GraduateTrial.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdWordsSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.ADWORDS)
            .fromFile()
            .build()
            .generateCredential();

    // Construct an AdWordsSession.
    session =
        new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();

  GraduateTrialParams params = new GraduateTrialParams();
  if (!params.parseArguments(args)) {
    // Either pass the required parameters for this example on the command line, or insert them
    // into the code here. See the parameter class definition above for descriptions.
    params.trialId = Long.parseLong("INSERT_TRIAL_ID_HERE");
  }

  try {
    runExample(adWordsServices, session, params.trialId);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the adwords.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf(
        "Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #24
Source File: GetAllActivityGroups.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  try {
    runExample(adManagerServices, session);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #25
Source File: GetProposalLineItemsForProposal.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  GetProposalLineItemsForProposalParams params = new GetProposalLineItemsForProposalParams();
  if (!params.parseArguments(args)) {
    // Either pass the required parameters for this example on the command line, or insert them
    // into the code here. See the parameter class definition above for descriptions.
    params.proposalId = Long.parseLong("INSERT_PROPOSAL_ID_HERE");
  }

  try {
    runExample(adManagerServices, session, params.proposalId);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #26
Source File: GetAllTrafficForecastSegments.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  try {
    runExample(adManagerServices, session);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #27
Source File: UpdateLabels.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  UpdateLabelsParams params = new UpdateLabelsParams();
  if (!params.parseArguments(args)) {
    // Either pass the required parameters for this example on the command line, or insert them
    // into the code here. See the parameter class definition above for descriptions.
    params.labelId = Long.parseLong("INSERT_LABEL_ID_HERE");
  }

  try {
    runExample(adManagerServices, session, params.labelId);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #28
Source File: GetSystemDefinedCreativeTemplates.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  try {
    runExample(adManagerServices, session);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #29
Source File: GetAllAudienceSegments.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  try {
    runExample(adManagerServices, session);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}
 
Example #30
Source File: DeactivatePlacements.java    From googleads-java-lib with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  AdManagerSession session;
  try {
    // Generate a refreshable OAuth2 credential.
    Credential oAuth2Credential =
        new OfflineCredentials.Builder()
            .forApi(Api.AD_MANAGER)
            .fromFile()
            .build()
            .generateCredential();

    // Construct a AdManagerSession.
    session =
        new AdManagerSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
  } 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 (OAuthException oe) {
    System.err.printf(
        "Failed to create OAuth credentials. Check OAuth settings in the %s file. "
            + "Exception: %s%n",
        DEFAULT_CONFIGURATION_FILENAME, oe);
    return;
  }

  AdManagerServices adManagerServices = new AdManagerServices();

  DeactivatePlacementsParams params = new DeactivatePlacementsParams();
  if (!params.parseArguments(args)) {
    // Either pass the required parameters for this example on the command line, or insert them
    // into the code here. See the parameter class definition above for descriptions.
    params.placementId = Long.parseLong("INSERT_PLACEMENT_ID_HERE");
  }

  try {
    runExample(adManagerServices, session, params.placementId);
  } catch (ApiException apiException) {
    // ApiException is the base class for most exceptions thrown by an API request. Instances
    // of this exception have a message and a collection of ApiErrors that indicate the
    // type and underlying cause of the exception. Every exception object in the admanager.axis
    // packages will return a meaningful value from toString
    //
    // ApiException extends RemoteException, so this catch block must appear before the
    // catch block for RemoteException.
    System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
    if (apiException.getErrors() != null) {
      int i = 0;
      for (ApiError apiError : apiException.getErrors()) {
        System.err.printf("  Error %d: %s%n", i++, apiError);
      }
    }
  } catch (RemoteException re) {
    System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
  }
}