Search in sources :

Example 1 with AdGroupBidModifierServiceInterface

use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierServiceInterface in project googleads-java-lib by googleads.

the class AddAdGroupBidModifier method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group where bid modifiers will be added.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long adGroupId) throws RemoteException {
    // Get the AdGroupBidModifierService.
    AdGroupBidModifierServiceInterface adGroupBidModifierService = adWordsServices.get(session, AdGroupBidModifierServiceInterface.class);
    // Create mobile platform. The ID can be found in the documentation.
    // https://developers.google.com/adwords/api/docs/appendix/platforms
    Platform mobile = new Platform();
    mobile.setId(30001L);
    AdGroupBidModifier adGroupBidModifier = new AdGroupBidModifier();
    adGroupBidModifier.setAdGroupId(adGroupId);
    adGroupBidModifier.setBidModifier(BID_MODIFIER);
    adGroupBidModifier.setCriterion(mobile);
    // Create ADD operation.
    AdGroupBidModifierOperation operation = new AdGroupBidModifierOperation();
    operation.setOperand(adGroupBidModifier);
    // Use 'ADD' to add a new modifier and 'SET' to update an existing one. A
    // modifier can be removed with the 'REMOVE' operator.
    operation.setOperator(Operator.ADD);
    // Update ad group bid modifier.
    AdGroupBidModifierReturnValue result = adGroupBidModifierService.mutate(new AdGroupBidModifierOperation[] { operation });
    for (AdGroupBidModifier bidModifierResult : result.getValue()) {
        System.out.printf("Campaign ID %d, ad group ID %d was updated with ad group level modifier: %.4f%n", bidModifierResult.getCampaignId(), bidModifierResult.getAdGroupId(), bidModifierResult.getBidModifier());
    }
}
Also used : AdGroupBidModifierReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierReturnValue) Platform(com.google.api.ads.adwords.axis.v201809.cm.Platform) AdGroupBidModifier(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifier) AdGroupBidModifierServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierServiceInterface) AdGroupBidModifierOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierOperation)

Example 2 with AdGroupBidModifierServiceInterface

use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierServiceInterface in project googleads-java-lib by googleads.

the class GetAdGroupBidModifier method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    // Get the AdGroupBidModifierService.
    AdGroupBidModifierServiceInterface adGroupBidModifierService = adWordsServices.get(session, AdGroupBidModifierServiceInterface.class);
    // Create selector.
    Selector selector = new SelectorBuilder().fields(AdGroupBidModifierField.CampaignId, AdGroupBidModifierField.AdGroupId, AdGroupBidModifierField.BidModifier, AdGroupBidModifierField.Id).offset(0).limit(PAGE_SIZE).build();
    AdGroupBidModifierPage page = adGroupBidModifierService.get(selector);
    if (page.getEntries() != null) {
        for (AdGroupBidModifier bidModifierResult : page.getEntries()) {
            String bidModifierValue = bidModifierResult.getBidModifier() != null ? bidModifierResult.getBidModifier().toString() : "unset";
            System.out.printf("Campaign ID %d, AdGroup ID %d, Criterion ID %d, " + "has ad group level modifier: %s%n", bidModifierResult.getCampaignId(), bidModifierResult.getAdGroupId(), bidModifierResult.getCriterion().getId(), bidModifierValue);
        }
    } else {
        System.out.println("No ad group level bid modifiers were found.");
    }
}
Also used : SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) AdGroupBidModifier(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifier) AdGroupBidModifierServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierServiceInterface) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) AdGroupBidModifierPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierPage)

Aggregations

AdGroupBidModifier (com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifier)2 AdGroupBidModifierServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierServiceInterface)2 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 AdGroupBidModifierOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierOperation)1 AdGroupBidModifierPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierPage)1 AdGroupBidModifierReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierReturnValue)1 Platform (com.google.api.ads.adwords.axis.v201809.cm.Platform)1 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)1