com.google.api.ads.adwords.axis.factory.AdWordsServices Java Examples

The following examples show how to use com.google.api.ads.adwords.axis.factory.AdWordsServices. 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: AdWordsApiUtil.java    From keyword-optimizer with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes this utility (credentials, sessions, ...).
 * 
 * @throws OAuthException in case of an authentication error
 * @throws ValidationException in case there is no refresh token
 * @throws ConfigurationLoadException in case of an error loading the config file
 */
private void init() throws OAuthException, ValidationException, ConfigurationLoadException {
  logger.info("Initializing session and services interface");
  
  try {
    // Generate a refreshable OAuth2 credential similar to a ClientLogin token
    // and can be used in place of a service account.
    Credential oAuth2Credential = new OfflineCredentials.Builder()
            .forApi(Api.ADWORDS)
            .fromFile(configPath)
            .build()
            .generateCredential();
    
    // Construct an AdWordsSession.
    String userAgentFromConfig = getUserAgentFromConfig();
    session = new AdWordsSession.Builder()
        .fromFile(configPath)
        .withUserAgent(PREFIX_USER_AGENT + userAgentFromConfig)
        .withOAuth2Credential(oAuth2Credential)
        .build();

    // Create the services interface object.
    services = new AdWordsServicesWithRateLimiter(AdWordsServices.getInstance());
  } catch (ValidationException e) {
    if ("refreshToken".equalsIgnoreCase(e.getTrigger())) {
      retrieveRefreshToken();
    } else {
      logger.error("General exception", e);
    }

    throw new OAuthException("Please add your refreshToken to your ads.properties file", e);
  }
}
 
Example #2
Source File: AdWordsAxisSoapIntegrationTest.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Submits a BudgetService.mutate call to the test server and asserts that the response contains
 * expected values.
 */
private void testBudgetServiceMutateRequest(AdWordsSession session) throws RemoteException,
    ApiException, IOException, SAXException {
  BudgetServiceInterface companyService =
      new AdWordsServices().get(session, BudgetServiceInterface.class);

  Budget budget = new Budget();
  budget.setName("Test Budget Name");
  Money money = new Money();
  money.setMicroAmount(50000000L);
  budget.setAmount(money);
  budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);

  BudgetOperation operation = new BudgetOperation();
  operation.setOperand(budget);
  operation.setOperator(Operator.ADD);

  Budget responseBudget = companyService.mutate(new BudgetOperation[] {operation}).getValue(0);

  assertEquals("Budget ID does not match", 251877074L, responseBudget.getBudgetId().longValue());
  assertEquals("Budget name does not match", budget.getName(), responseBudget.getName());
  assertEquals("Budget amount does not match", budget.getAmount().getMicroAmount(),
      responseBudget.getAmount().getMicroAmount());
  assertEquals("Budget delivery method does not match", budget.getDeliveryMethod(),
      responseBudget.getDeliveryMethod());

  assertFalse("Did not request compression but request was compressed",
      testHttpServer.wasLastRequestBodyCompressed());
  XMLAssert.assertXMLEqual(SoapRequestXmlProvider.getOAuth2SoapRequest(API_VERSION),
      testHttpServer.getLastRequestBody());
}
 
Example #3
Source File: AddAudience.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 #4
Source File: HandlePartialFailures.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();

  HandlePartialFailuresParams params = new HandlePartialFailuresParams();
  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.adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
  }

  try {
    runExample(adWordsServices, session, params.adGroupId);
  } 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 #5
Source File: RemoveAdGroup.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();

  RemoveAdGroupParams params = new RemoveAdGroupParams();
  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.adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
  }

  try {
    runExample(adWordsServices, session, params.adGroupId);
  } 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 #6
Source File: AddAdGroups.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();

  AddAdGroupsParams params = new AddAdGroupsParams();
  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 #7
Source File: GetAccountChanges.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 #8
Source File: GetProductCategoryTaxonomy.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 #9
Source File: AddSmartShoppingAd.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();

  AddSmartShoppingAdParams params = new AddSmartShoppingAdParams();
  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.merchantId = Long.parseLong("INSERT_MERCHANT_ID_HERE");
    params.createDefaultPartition = false;
  }

  try {
    runExample(adWordsServices, session, params.merchantId, params.createDefaultPartition);
  } 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: AddShoppingCampaign.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();

  AddShoppingCampaignParams params = new AddShoppingCampaignParams();
  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.budgetId = Long.parseLong("INSERT_BUDGET_ID_HERE");
    params.merchantId = Long.parseLong("INSERT_MERCHANT_ID_HERE");
    params.createDefaultPartition = false;
  }

  try {
    runExample(adWordsServices, session, params.budgetId, params.merchantId,
        params.createDefaultPartition);
  } 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 #11
Source File: AddProductScope.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();

  
  AddProductScopeParams params = new AddProductScopeParams();
  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 #12
Source File: UploadImageAsset.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);
  } catch (IOException ioe) {
    System.err.printf("Example failed due to IOException: %s%n", ioe);
  }
}
 
Example #13
Source File: UploadImage.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);
  } catch (IOException ioe) {
    System.err.printf("Example failed due to IOException: %s%n", ioe);
  }
}
 
Example #14
Source File: GetAllImagesAndVideos.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 #15
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 #16
Source File: AddCrmBasedUserList.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);
  } catch (UnsupportedEncodingException ue) {
    System.err.printf("Example failed due to encoding exception: %s%n", ue);
  }
}
 
Example #17
Source File: AddRuleBasedUserLists.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 #18
Source File: AddSiteLinksUsingFeeds.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();

  AddSiteLinksUsingFeedsParams params = new AddSiteLinksUsingFeedsParams();
  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");
    params.feedName = "INSERT_FEED_NAME_HERE";
    // Optional: Ad group to restrict targeting to.
    params.adGroupId = null;
  }

  try {
    runExample(adWordsServices, session, params.campaignId, params.feedName, params.adGroupId);
  } 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 #19
Source File: UpdateCampaign.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();

  UpdateCampaignParams params = new UpdateCampaignParams();
  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 #20
Source File: GetCampaignsWithAwql.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 #21
Source File: RemoveAd.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();

  RemoveAdParams params = new RemoveAdParams();
  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.adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
    params.adId = Long.parseLong("INSERT_AD_ID_HERE");
  }

  try {
    runExample(adWordsServices, session, params.adGroupId, params.adId);
  } 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 #22
Source File: UploadOfflineConversions.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();



  UploadOfflineConversionsParams params = new UploadOfflineConversionsParams();
  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.conversionName = "INSERT_CONVERSION_NAME_HERE";
    params.gclId = "INSERT_GCL_ID_HERE";
    params.conversionTime = "INSERT_CONVERSION_TIME_HERE";
    params.conversionValue = Double.parseDouble("INSERT_CONVERSION_VALUE_HERE");
  }

  try {
    runExample(
        adWordsServices,
        session,
        params.conversionName,
        params.gclId,
        params.conversionTime,
        params.conversionValue);
  } 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 #23
Source File: UploadOfflineData.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();

  UploadOfflineDataParams params = new UploadOfflineDataParams();
  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.emailAddresses =
        Arrays.asList("INSERT_EMAIL_ADDRESS_1_HERE", "INSERT_EMAIL_ADDRESS_2_HERE");
    params.conversionName = "INSERT_CONVERSION_NAME_HERE";
    params.externalUploadId = Long.valueOf("INSERT_EXTERNAL_UPLOAD_ID_HERE");

    // Change the enum below to STORE_SALES_UPLOAD_THIRD_PARTY if uploading third party data.
    params.offlineDataUploadType =
        OfflineDataUploadType.STORE_SALES_UPLOAD_FIRST_PARTY.getValue();

    // The three constants below are needed when uploading third party data.
    // You can safely ignore them if you are uploading first party data.
    // For times, use the format yyyyMMdd HHmmss tz. For more details on formats, see:
    // https://developers.google.com/adwords/api/docs/appendix/codes-formats#date-and-time-formats
    // For time zones, see:
    // https://developers.google.com/adwords/api/docs/appendix/codes-formats#timezone-ids
    params.advertiserUploadTime = "INSERT_ADVERTISER_UPLOAD_TIME";
    params.bridgeMapVersionId = "INSERT_BRIDGE_MAP_VERSION_ID";
    params.partnerId = Integer.valueOf("INSERT_PARTNER_ID");
  }

  OfflineDataUploadType uploadTypeEnum =
      OfflineDataUploadType.fromString(params.offlineDataUploadType);

  // Set partial failure to true since this example demonstrates how to handle partial
  // failure errors.
  session.setPartialFailure(true);
  try {
    runExample(
        adWordsServices,
        session,
        params.conversionName,
        params.externalUploadId,
        params.emailAddresses,
        uploadTypeEnum,
        params.advertiserUploadTime,
        params.bridgeMapVersionId,
        params.partnerId);
  } 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);
  } catch (UnsupportedEncodingException ue) {
    System.err.printf("Example failed due to encoding exception: %s%n", ue);
  }
}
 
Example #24
Source File: GetTargetableLanguagesAndCarriers.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 #25
Source File: AddDemographicTargetingCriteria.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();

  AddDemographicTargetingCriteriaParams params = new AddDemographicTargetingCriteriaParams();
  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.adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
  }

  try {
    runExample(adWordsServices, session, params.adGroupId);
  } 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 #26
Source File: GetCampaignTargetingCriteria.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 #27
Source File: AddCustomerNegativeCriteria.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 #28
Source File: AddCampaignTargetingCriteria.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();

  AddCampaignTargetingCriteriaParams params = new AddCampaignTargetingCriteriaParams();
  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");
    params.locationFeedId = Long.parseLong("INSERT_LOCATION_FEED_ID_HERE");
  }

  try {
    runExample(adWordsServices, session, params.campaignId, params.locationFeedId);
  } 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 #29
Source File: LookupLocation.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();

  String[] locationNames = new String[] {"Paris", "Quebec", "Spain", "Deutschland"};

  try {
    runExample(adWordsServices, session, locationNames);
  } 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 #30
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);
  }
}