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

The following examples show how to use com.google.api.ads.common.lib.auth.OfflineCredentials. 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: CreateAdManagerSessionWithoutPropertiesFile.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
private static AdManagerSession createAdManagerSession(
    String jsonKeyFilePath, String applicationName, String networkCode)
    throws OAuthException, ValidationException {
  // Create a valid OAuth2 credential without using a properties file.
  Credential credential =
      new OfflineCredentials.Builder()
          .forApi(Api.AD_MANAGER)
          .withJsonKeyFilePath(jsonKeyFilePath)
          .build()
          .generateCredential();

  // Create a new AdManagerSession without using a properties file.
  return new AdManagerSession.Builder()
      .withOAuth2Credential(credential)
      .withApplicationName(applicationName)
      .withNetworkCode(networkCode)
      .build();
}
 
Example #2
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 #3
Source File: GetImageCreatives.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 #4
Source File: GetUserTeamAssociationsForUser.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();

  GetUserTeamAssociationsForUserParams params = new GetUserTeamAssociationsForUserParams();
  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.userId = Long.parseLong("INSERT_USER_ID_HERE");
  }

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

  CreateNativeCreativesParams params = new CreateNativeCreativesParams();
  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 #6
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 #7
Source File: GetProposalsAwaitingSellerReview.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 #8
Source File: GetPredefinedCustomTargetingKeysAndValues.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 #9
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 #10
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 #11
Source File: DeactivateCustomFields.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();

  DeactivateCustomFieldsParams params = new DeactivateCustomFieldsParams();
  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.customFieldId = Long.parseLong("INSERT_CUSTOM_FIELD_ID_HERE");
  }

  try {
    runExample(adManagerServices, session, params.customFieldId);
  } 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: GetCampaignCriterionBidModifierSimulations.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();

  GetCampaignCriterionBidModifierSimulationsParams params =
      new GetCampaignCriterionBidModifierSimulationsParams();
  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 #13
Source File: CreateCreatives.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();

  CreateCreativesParams params = new CreateCreativesParams();
  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: AddMultiAssetResponsiveDisplayAd.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();

  AddMultiAssetResponsiveDisplayAdParams params = new AddMultiAssetResponsiveDisplayAdParams();
  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);
  } catch (IOException ioe) {
    System.err.printf("Example failed unexpectedly due to IOException: %s%n", ioe);
  }
}
 
Example #15
Source File: AddPrices.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();

  AddPricesParams params = new AddPricesParams();
  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 #16
Source File: GetActiveActivityGroups.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 #17
Source File: UpdateLicas.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();

  UpdateLicasParams params = new UpdateLicasParams();
  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");
    params.creativeId = Long.parseLong("INSERT_CREATIVE_ID_HERE");
  }

  try {
    runExample(adManagerServices, session, params.lineItemId, params.creativeId);
  } 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: CreateProposals.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();

  CreateProposalsParams params = new CreateProposalsParams();
  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.primarySalespersonId = Long.parseLong("INSERT_PRIMARY_SALESPERSON_ID_HERE");
    params.primaryTraffickerId = Long.parseLong("INSERT_PRIMARY_TRAFFICKER_ID_HERE");
    params.programmaticBuyerId = Long.parseLong("INSERT_PROGRAMMATIC_BUYER_ID_HERE");
  }

  try {
    runExample(
        adManagerServices,
        session,
        params.primarySalespersonId,
        params.primaryTraffickerId,
        params.programmaticBuyerId);
  } 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: GetAllRoles.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 #20
Source File: CreateContacts.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();

  CreateContactsParams params = new CreateContactsParams();
  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");
    params.agencyId = Long.parseLong("INSERT_AGENCY_ID_HERE");
  }

  try {
    runExample(adManagerServices, session, params.advertiserId, params.agencyId);
  } 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: DeactivateCustomFields.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();

  DeactivateCustomFieldsParams params = new DeactivateCustomFieldsParams();
  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.customFieldId = Long.parseLong("INSERT_CUSTOM_FIELD_ID_HERE");
  }

  try {
    runExample(adManagerServices, session, params.customFieldId);
  } 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: CreateProposals.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();

  CreateProposalsParams params = new CreateProposalsParams();
  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.primarySalespersonId = Long.parseLong("INSERT_PRIMARY_SALESPERSON_ID_HERE");
    params.primaryTraffickerId = Long.parseLong("INSERT_PRIMARY_TRAFFICKER_ID_HERE");
    params.programmaticBuyerId = Long.parseLong("INSERT_PROGRAMMATIC_BUYER_ID_HERE");
  }

  try {
    runExample(
        adManagerServices,
        session,
        params.primarySalespersonId,
        params.primaryTraffickerId,
        params.programmaticBuyerId);
  } 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: 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 #24
Source File: UpdateTrafficAdjustments.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();

  UpdateTrafficAdjustmentsParams params = new UpdateTrafficAdjustmentsParams();
  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.adjustmentId = Long.parseLong("INSERT_ADJUSTMENT_ID_HERE");
  }

  try {
    runExample(adManagerServices, session, params.adjustmentId);
  } 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: GetAllUsers.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 #26
Source File: GetAllTargetingPresets.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: UploadConversionAdjustment.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.adjustmentType = "INSERT_ADJUSTMENT_TYPE_HERE";
    params.conversionTime = "INSERT_CONVERSION_TIME_HERE";
    params.adjustmentTime = "INSERT_ADJUSTMENT_TIME_HERE";
    // Optional: Adjusted value for adjustment type RESTATE.
    params.adjustedValue = Double.parseDouble("INSERT_ADJUSTED_VALUE_HERE");
  }

  OfflineConversionAdjustmentType adjustmentTypeEnum =
      OfflineConversionAdjustmentType.fromString(params.adjustmentType);

  try {
    runExample(
        adWordsServices,
        session,
        params.conversionName,
        params.gclId,
        adjustmentTypeEnum,
        params.conversionTime,
        params.adjustmentTime,
        params.adjustedValue);
  } 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: UpdateCustomFields.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();

  UpdateCustomFieldsParams params = new UpdateCustomFieldsParams();
  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.customFieldId = Long.parseLong("INSERT_CUSTOM_FIELD_ID_HERE");
  }

  try {
    runExample(adManagerServices, session, params.customFieldId);
  } 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: UpdateCreativeSets.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();

  UpdateCreativeSetsParams params = new UpdateCreativeSetsParams();
  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.creativeSetId = Long.parseLong("INSERT_CREATIVE_SET_ID_HERE");
    params.companionCreativeId = Long.parseLong("INSERT_COMPANION_CREATIVE_ID_HERE");
  }

  try {
    runExample(adManagerServices, session, params.creativeSetId, params.companionCreativeId);
  } 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: DeactivateLabels.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();

  DeactivateLabelsParams params = new DeactivateLabelsParams();
  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);
  }
}