com.google.protobuf.StringValue Java Examples
The following examples show how to use
com.google.protobuf.StringValue.
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: GeoTargetConstantServiceClientTest.java From google-ads-java with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("all") public void suggestGeoTargetConstantsExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockGeoTargetConstantService.addException(exception); try { StringValue locale = StringValue.newBuilder().build(); StringValue countryCode = StringValue.newBuilder().build(); client.suggestGeoTargetConstants(locale, countryCode); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
Example #2
Source File: AddPrices.java From google-ads-java with Apache License 2.0 | 6 votes |
/** * Creates a new price offer with the specified parameters. * * @param header the headline for the price extension. * @param description a detailed description line that may show on the price extension. * @param priceInMicros the price to display, measured in micros (e.g. 1_000_000 micros = 1 USD). * @param currencyCode the currency code representing the unit of currency. * @param unit optionally set a unit describing the quantity obtained for the price. * @param finalUrl the final URL to which a click on the price extension drives traffic. * @param finalMobileUrl the final URL to which mobile clicks on the price extension drives * traffic. * @return a newly created price offer object. */ private PriceOffer createPriceOffer( String header, String description, int priceInMicros, String currencyCode, PriceExtensionPriceUnit unit, String finalUrl, String finalMobileUrl) { PriceOffer.Builder priceBuilder = PriceOffer.newBuilder() .setHeader(StringValue.of(header)) .setDescription(StringValue.of(description)) .addFinalUrls(StringValue.of(finalUrl)) .setPrice( Money.newBuilder() .setAmountMicros(Int64Value.of(priceInMicros)) .setCurrencyCode(StringValue.of(currencyCode))) .setUnit(unit); // Optional: Sets the final mobile URLs. if (finalMobileUrl != null) { priceBuilder.addFinalMobileUrls(StringValue.of(finalMobileUrl)); } return priceBuilder.build(); }
Example #3
Source File: GeoTargetConstantServiceClientTest.java From google-ads-java with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("all") public void suggestGeoTargetConstantsTest() { SuggestGeoTargetConstantsResponse expectedResponse = SuggestGeoTargetConstantsResponse.newBuilder().build(); mockGeoTargetConstantService.addResponse(expectedResponse); StringValue locale = StringValue.newBuilder().build(); StringValue countryCode = StringValue.newBuilder().build(); SuggestGeoTargetConstantsResponse actualResponse = client.suggestGeoTargetConstants(locale, countryCode); Assert.assertEquals(expectedResponse, actualResponse); List<AbstractMessage> actualRequests = mockGeoTargetConstantService.getRequests(); Assert.assertEquals(1, actualRequests.size()); SuggestGeoTargetConstantsRequest actualRequest = (SuggestGeoTargetConstantsRequest) actualRequests.get(0); Assert.assertEquals(locale, actualRequest.getLocale()); Assert.assertEquals(countryCode, actualRequest.getCountryCode()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
Example #4
Source File: AddKeywordPlan.java From google-ads-java with Apache License 2.0 | 6 votes |
/** * Creates a keyword plan. * * @param googleAdsClient the Google Ads API client. * @param customerId the client customer ID. */ private static String createKeywordPlan(GoogleAdsClient googleAdsClient, Long customerId) { KeywordPlan plan = KeywordPlan.newBuilder() .setName( StringValue.of("Keyword plan for traffic estimate #" + System.currentTimeMillis())) .setForecastPeriod( KeywordPlanForecastPeriod.newBuilder() .setDateInterval(KeywordPlanForecastInterval.NEXT_QUARTER) .build()) .build(); KeywordPlanOperation op = KeywordPlanOperation.newBuilder().setCreate(plan).build(); try (KeywordPlanServiceClient client = googleAdsClient.getLatestVersion().createKeywordPlanServiceClient()) { // Adds the keyword plan. MutateKeywordPlansResponse response = client.mutateKeywordPlans(String.valueOf(customerId), Arrays.asList(op)); // Displays the results. String resourceName = response.getResults(0).getResourceName(); System.out.printf("Created keyword plan: %s%n", resourceName); return resourceName; } }
Example #5
Source File: AddCampaignTargetingCriteria.java From google-ads-java with Apache License 2.0 | 6 votes |
/** * Creates a campaign criterion from an address and proximity radius. * * @param campaignResourceName the campaign resource name to target. * @return a campaign criterion object with the specified address and targeting radius. */ private static CampaignCriterion buildProximityLocation(String campaignResourceName) { Builder builder = CampaignCriterion.newBuilder().setCampaign(StringValue.of(campaignResourceName)); ProximityInfo.Builder proximityBuilder = builder.getProximityBuilder(); proximityBuilder.setRadius(DoubleValue.of(10.0)).setRadiusUnits(ProximityRadiusUnits.MILES); AddressInfo.Builder addressBuilder = proximityBuilder.getAddressBuilder(); addressBuilder .setStreetAddress(StringValue.of("38 avenue de l'Opéra")) .setCityName(StringValue.of("Paris")) .setPostalCode(StringValue.of("75002")) .setCountryCode(StringValue.of("FR")); return builder.build(); }
Example #6
Source File: GrpcAnnotationValueMapper.java From pinpoint with Apache License 2.0 | 6 votes |
private PLongIntIntByteByteStringValue newLongIntIntByteByteStringValue(LongIntIntByteByteStringValue v) { final PLongIntIntByteByteStringValue.Builder builder = PLongIntIntByteByteStringValue.newBuilder(); builder.setLongValue(v.getLongValue()); builder.setIntValue1(v.getIntValue1()); if (v.getIntValue2() != -1) { builder.setIntValue2(v.getIntValue2()); } if (v.getByteValue1() != -1) { builder.setByteValue1(v.getByteValue1()); } if (v.getByteValue2() != -1) { builder.setByteValue2(v.getByteValue2()); } if (v.getStringValue() != null) { StringValue stringValue = newStringValue(v.getStringValue()); builder.setStringValue(stringValue); } return builder.build(); }
Example #7
Source File: GeoTargetConstantServiceClientTest.java From google-ads-java with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("all") public void suggestGeoTargetConstantsTest() { SuggestGeoTargetConstantsResponse expectedResponse = SuggestGeoTargetConstantsResponse.newBuilder().build(); mockGeoTargetConstantService.addResponse(expectedResponse); StringValue locale = StringValue.newBuilder().build(); StringValue countryCode = StringValue.newBuilder().build(); SuggestGeoTargetConstantsResponse actualResponse = client.suggestGeoTargetConstants(locale, countryCode); Assert.assertEquals(expectedResponse, actualResponse); List<AbstractMessage> actualRequests = mockGeoTargetConstantService.getRequests(); Assert.assertEquals(1, actualRequests.size()); SuggestGeoTargetConstantsRequest actualRequest = (SuggestGeoTargetConstantsRequest) actualRequests.get(0); Assert.assertEquals(locale, actualRequest.getLocale()); Assert.assertEquals(countryCode, actualRequest.getCountryCode()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
Example #8
Source File: InteractiveApi.java From java-bot-sdk with Apache License 2.0 | 6 votes |
private InteractiveMediaWidget buildSelectMenu(InteractiveSelect select) { InteractiveMediaSelect.Builder apiSelect = InteractiveMediaSelect.newBuilder(); for (InteractiveSelectOption selectOption : select.getOptions()) { InteractiveMediaSelectOption.Builder apiSelectOption = InteractiveMediaSelectOption.newBuilder(); apiSelectOption.setValue(selectOption.getValue()).setLabel(selectOption.getLabel()); apiSelect.addOptions(apiSelectOption); } if (select.getLabel() != null && !select.getLabel().isEmpty()) { apiSelect.setLabel(StringValue.of(select.getLabel())); } if (select.getDefaultValue() != null && !select.getDefaultValue().isEmpty()) { apiSelect.setDefaultValue(StringValue.of(select.getDefaultValue())); } return InteractiveMediaWidget.newBuilder().setInteractiveMediaSelect(apiSelect).build(); }
Example #9
Source File: GrpcServiceServerTest.java From armeria with Apache License 2.0 | 6 votes |
@Override public void errorWithMessage(SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) { final Metadata metadata = new Metadata(); metadata.put(STRING_VALUE_KEY, StringValue.newBuilder().setValue("custom metadata").build()); metadata.put(CUSTOM_VALUE_KEY, "custom value"); final ServiceRequestContext ctx = ServiceRequestContext.current(); // gRPC wire format allow comma-separated binary headers. ctx.mutateAdditionalResponseTrailers( mutator -> mutator.add( INT_32_VALUE_KEY.name(), Base64.getEncoder().encodeToString( Int32Value.newBuilder().setValue(10).build().toByteArray()) + ',' + Base64.getEncoder().encodeToString( Int32Value.newBuilder().setValue(20).build().toByteArray()))); responseObserver.onError(Status.ABORTED.withDescription("aborted call").asException(metadata)); }
Example #10
Source File: GrpcServiceServerTest.java From armeria with Apache License 2.0 | 6 votes |
@ParameterizedTest @ArgumentsSource(BlockingClientProvider.class) void error_withMessage(UnitTestServiceBlockingStub blockingClient) throws Exception { final StatusRuntimeException t = (StatusRuntimeException) catchThrowable( () -> blockingClient.errorWithMessage(REQUEST_MESSAGE)); assertThat(t.getStatus().getCode()).isEqualTo(Code.ABORTED); assertThat(t.getStatus().getDescription()).isEqualTo("aborted call"); assertThat(t.getTrailers().getAll(STRING_VALUE_KEY)) .containsExactly(StringValue.newBuilder().setValue("custom metadata").build()); assertThat(t.getTrailers().getAll(INT_32_VALUE_KEY)) .containsExactly(Int32Value.newBuilder().setValue(10).build(), Int32Value.newBuilder().setValue(20).build()); assertThat(t.getTrailers().get(CUSTOM_VALUE_KEY)).isEqualTo("custom value"); checkRequestLog((rpcReq, rpcRes, grpcStatus) -> { assertThat(rpcReq.method()).isEqualTo("armeria.grpc.testing.UnitTestService/ErrorWithMessage"); assertThat(rpcReq.params()).containsExactly(REQUEST_MESSAGE); assertThat(grpcStatus).isNotNull(); assertThat(grpcStatus.getCode()).isEqualTo(Code.ABORTED); assertThat(grpcStatus.getDescription()).isEqualTo("aborted call"); }); }
Example #11
Source File: InteractiveApi.java From java-bot-sdk with Apache License 2.0 | 6 votes |
private InteractiveMediaConfirm.Builder buildConfirm(InteractiveAction action) { InteractiveMediaConfirm.Builder confirm = InteractiveMediaConfirm.newBuilder(); if (action.getConfirm().getText() != null) { confirm.setText(StringValue.of(action.getConfirm().getText())); } if (action.getConfirm().getTitle() != null) { confirm.setTitle(StringValue.of(action.getConfirm().getTitle())); } if (action.getConfirm().getOk() != null) { confirm.setOk(StringValue.of(action.getConfirm().getOk())); } if (action.getConfirm().getDismiss() != null) { confirm.setDismiss(StringValue.of(action.getConfirm().getDismiss())); } return confirm; }
Example #12
Source File: SetupRemarketing.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Creates a campaign criterion that targets a user list with a campaign. * * @param googleAdsClient the Google Ads API client. * @param customerId the client customer ID. * @param campaignId the campaign on which the user list will be targeted. * @param userList the resource name of the user list to be targeted. * @return the campaign criterion resource name. */ private String targetAdsInCampaignToUserList( GoogleAdsClient googleAdsClient, long customerId, long campaignId, String userList) { // Creates the campaign criterion. CampaignCriterion campaignCriterion = CampaignCriterion.newBuilder() .setCampaign(StringValue.of(ResourceNames.campaign(customerId, campaignId))) .setUserList(UserListInfo.newBuilder().setUserList(StringValue.of(userList)).build()) .build(); // Creates the operation. CampaignCriterionOperation operation = CampaignCriterionOperation.newBuilder().setCreate(campaignCriterion).build(); // Creates the campaign criterion service client. try (CampaignCriterionServiceClient campaignCriterionServiceClient = googleAdsClient.getLatestVersion().createCampaignCriterionServiceClient()) { // Adds the campaign criterion. MutateCampaignCriteriaResponse response = campaignCriterionServiceClient.mutateCampaignCriteria( Long.toString(customerId), ImmutableList.of(operation)); // Gets and prints the campaign criterion resource name. String campaignCriterionResourceName = response.getResults(0).getResourceName(); System.out.printf( "Successfully created campaign criterion with resource name '%s' " + "targeting user list with resource name '%s' with campaign with ID %d.%n", campaignCriterionResourceName, userList, campaignId); return campaignCriterionResourceName; } }
Example #13
Source File: WrappedPrimitiveTest.java From jackson-datatype-protobuf with Apache License 2.0 | 5 votes |
private static HasWrappedPrimitives defaultPopulatedMessage() { return HasWrappedPrimitives .newBuilder() .setDoubleWrapper(DoubleValue.getDefaultInstance()) .setFloatWrapper(FloatValue.getDefaultInstance()) .setInt64Wrapper(Int64Value.getDefaultInstance()) .setUint64Wrapper(UInt64Value.getDefaultInstance()) .setInt32Wrapper(Int32Value.getDefaultInstance()) .setUint32Wrapper(UInt32Value.getDefaultInstance()) .setBoolWrapper(BoolValue.getDefaultInstance()) .setStringWrapper(StringValue.getDefaultInstance()) .setBytesWrapper(BytesValue.getDefaultInstance()) .build(); }
Example #14
Source File: KeywordPlanIdeaServiceClientTest.java From google-ads-java with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("all") public void generateKeywordIdeasTest() { GenerateKeywordIdeaResponse expectedResponse = GenerateKeywordIdeaResponse.newBuilder().build(); mockKeywordPlanIdeaService.addResponse(expectedResponse); String customerId = "customerId-1772061412"; StringValue language = StringValue.newBuilder().build(); List<StringValue> geoTargetConstants = new ArrayList<>(); KeywordPlanNetworkEnum.KeywordPlanNetwork keywordPlanNetwork = KeywordPlanNetworkEnum.KeywordPlanNetwork.UNSPECIFIED; GenerateKeywordIdeaResponse actualResponse = client.generateKeywordIdeas(customerId, language, geoTargetConstants, keywordPlanNetwork); Assert.assertEquals(expectedResponse, actualResponse); List<AbstractMessage> actualRequests = mockKeywordPlanIdeaService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GenerateKeywordIdeasRequest actualRequest = (GenerateKeywordIdeasRequest) actualRequests.get(0); Assert.assertEquals(customerId, actualRequest.getCustomerId()); Assert.assertEquals(language, actualRequest.getLanguage()); Assert.assertEquals(geoTargetConstants, actualRequest.getGeoTargetConstantsList()); Assert.assertEquals(keywordPlanNetwork, actualRequest.getKeywordPlanNetwork()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
Example #15
Source File: AddDynamicPageFeed.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Creates a feed. * * @param googleAdsClient the Google Ads API client. * @param customerId the customer ID in which to create the feed. * @return the resource name of the newly created feed. */ private static String createFeed(GoogleAdsClient googleAdsClient, long customerId) { // Creates a URL attribute. FeedAttribute urlAttribute = FeedAttribute.newBuilder() .setType(FeedAttributeType.URL_LIST) .setName(StringValue.of("Page URL")) .build(); // Creates a label attribute. FeedAttribute labelAttribute = FeedAttribute.newBuilder() .setType(FeedAttributeType.STRING_LIST) .setName(StringValue.of("Label")) .build(); // Creates the feed. Feed feed = Feed.newBuilder() .setName(StringValue.of("DSA Feed #" + System.currentTimeMillis())) .addAllAttributes(ImmutableList.of(urlAttribute, labelAttribute)) .build(); // Creates a feed operation for creating a feed. FeedOperation feedOperation = FeedOperation.newBuilder().setCreate(feed).build(); // Creates a feed service client. try (FeedServiceClient feedServiceClient = googleAdsClient.getLatestVersion().createFeedServiceClient()) { // Adds the feed. MutateFeedsResponse feedResponse = feedServiceClient.mutateFeeds(Long.toString(customerId), ImmutableList.of(feedOperation)); String feedResourceName = feedResponse.getResults(0).getResourceName(); System.out.printf("Added feed named '%s'.%n", feedResourceName); return feedResourceName; } }
Example #16
Source File: AddCustomerMatchUserList.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Creates a Customer Match user list. * * @param googleAdsClient the Google Ads API client. * @param customerId the client customer ID. * @return the resource name of the newly created user list. */ private String createCustomerMatchUserList(GoogleAdsClient googleAdsClient, long customerId) { // Creates the new user list. UserList userList = UserList.newBuilder() .setName(StringValue.of("Customer Match list #" + System.currentTimeMillis())) .setDescription( StringValue.of("A list of customers that originated from email addresses")) // Customer Match user lists can use a membership life span of 10,000 to indicate // unlimited; otherwise normal values apply. // Sets the membership life span to 30 days. .setMembershipLifeSpan(Int64Value.of(30)) // Sets the upload key type to indicate the type of identifier that will be used to // add users to the list. This field is immutable and required for an ADD operation. .setCrmBasedUserList( CrmBasedUserListInfo.newBuilder() .setUploadKeyType(CustomerMatchUploadKeyType.CONTACT_INFO)) .build(); // Creates the operation. UserListOperation operation = UserListOperation.newBuilder().setCreate(userList).build(); // Creates the service client. try (UserListServiceClient userListServiceClient = googleAdsClient.getLatestVersion().createUserListServiceClient()) { // Adds the user list. MutateUserListsResponse response = userListServiceClient.mutateUserLists( Long.toString(customerId), ImmutableList.of(operation)); // Prints the response. System.out.printf( "Created Customer Match user list with resource name: %s.%n", response.getResults(0).getResourceName()); return response.getResults(0).getResourceName(); } }
Example #17
Source File: AddDynamicSearchAds.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Adds a campaign. * * @param googleAdsClient the Google Ads API client. * @param customerId the client customer ID. * @param budgetResourceName the campaign budget resource name. * @return the campaign resource name. */ private static String addCampaign( GoogleAdsClient googleAdsClient, long customerId, String budgetResourceName) { // Creates the campaign. Campaign campaign = Campaign.newBuilder() .setName(StringValue.of("Interplanetary Cruise #" + System.currentTimeMillis())) .setAdvertisingChannelType(AdvertisingChannelType.SEARCH) .setStatus(CampaignStatus.PAUSED) .setManualCpc(ManualCpc.newBuilder().build()) .setCampaignBudget(StringValue.of(budgetResourceName)) // Enables the campaign for DSAs. .setDynamicSearchAdsSetting( DynamicSearchAdsSetting.newBuilder() .setDomainName(StringValue.of("example.com")) .setLanguageCode(StringValue.of("en")) .build()) .setStartDate(StringValue.of(new DateTime().plusDays(1).toString("yyyyMMdd"))) .setEndDate(StringValue.of(new DateTime().plusDays(30).toString("yyyyMMdd"))) .build(); // Creates the operation. CampaignOperation operation = CampaignOperation.newBuilder().setCreate(campaign).build(); // Creates the campaign service client. try (CampaignServiceClient campaignServiceClient = googleAdsClient.getLatestVersion().createCampaignServiceClient()) { // Adds the campaign. MutateCampaignsResponse response = campaignServiceClient.mutateCampaigns( Long.toString(customerId), ImmutableList.of(operation)); String campaignResourceName = response.getResults(0).getResourceName(); // Displays the results. System.out.printf("Added campaign with resource name '%s'.%n", campaignResourceName); return campaignResourceName; } }
Example #18
Source File: AddDynamicSearchAds.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Adds an expanded dynamic search ad. * * @param googleAdsClient the Google Ads API client. * @param customerId the client customer ID. * @param adGroupResourceName the ad group resource name. */ private static void addExpandedDSA( GoogleAdsClient googleAdsClient, long customerId, String adGroupResourceName) { // Creates an ad group ad. AdGroupAd adGroupAd = AdGroupAd.newBuilder() .setAdGroup(StringValue.of(adGroupResourceName)) .setStatus(AdGroupAdStatus.PAUSED) // Sets the ad as an expanded dynamic search ad .setAd( Ad.newBuilder() .setExpandedDynamicSearchAd( ExpandedDynamicSearchAdInfo.newBuilder() .setDescription(StringValue.of("Buy tickets now!")) .build()) .build()) .build(); // Creates the operation. AdGroupAdOperation operation = AdGroupAdOperation.newBuilder().setCreate(adGroupAd).build(); // Creates the ad group ad service client. try (AdGroupAdServiceClient adGroupAdServiceClient = googleAdsClient.getLatestVersion().createAdGroupAdServiceClient()) { // Adds the dynamic search ad. MutateAdGroupAdsResponse response = adGroupAdServiceClient.mutateAdGroupAds( Long.toString(customerId), ImmutableList.of(operation)); // Displays the response. System.out.printf( "Added ad group ad with resource name '%s'.%n", response.getResults(0).getResourceName()); } }
Example #19
Source File: GrpcSpanMessageConverter.java From pinpoint with Apache License 2.0 | 5 votes |
private PIntStringValue buildPIntStringValue(IntStringValue exceptionInfo) { PIntStringValue.Builder builder = PIntStringValue.newBuilder(); builder.setIntValue(exceptionInfo.getIntValue()); if (exceptionInfo.getStringValue() != null) { final StringValue stringValue = StringValue.of(exceptionInfo.getStringValue()); builder.setStringValue(stringValue); } return builder.build(); }
Example #20
Source File: AddSitelinks.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Creates a new SitelinkFeedItem with the specified attributes. * * @param sitelinkText the text of the sitelink feed item. * @param sitelinkUrl the URL of the sitelink feed item. */ private static SitelinkFeedItem createSitelinkFeedItem(String sitelinkText, String sitelinkUrl) { return SitelinkFeedItem.newBuilder() .setLinkText(StringValue.of(sitelinkText)) .addFinalUrls(StringValue.of(sitelinkUrl)) .build(); }
Example #21
Source File: SetupRemarketing.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Creates an ad group criterion that targets a user list with an ad group. * * @param googleAdsClient the Google Ads API client. * @param customerId the client customer ID. * @param adGroupId the ad group on which the user list will be targeted. * @param userList the resource name of the user list to be targeted. * @return the ad group criterion resource name. */ private String targetAdsInAdGroupToUserList( GoogleAdsClient googleAdsClient, long customerId, long adGroupId, String userList) { // Creates the ad group criterion targeting members of the user list. AdGroupCriterion adGroupCriterion = AdGroupCriterion.newBuilder() .setAdGroup(StringValue.of(ResourceNames.adGroup(customerId, adGroupId))) .setUserList(UserListInfo.newBuilder().setUserList(StringValue.of(userList)).build()) .build(); // Creates the operation. AdGroupCriterionOperation operation = AdGroupCriterionOperation.newBuilder().setCreate(adGroupCriterion).build(); // Creates the ad group criterion service. try (AdGroupCriterionServiceClient adGroupCriterionServiceClient = googleAdsClient.getLatestVersion().createAdGroupCriterionServiceClient()) { // Adds the ad group criterion. MutateAdGroupCriteriaResponse response = adGroupCriterionServiceClient.mutateAdGroupCriteria( Long.toString(customerId), ImmutableList.of(operation)); // Gets and prints the results. String adGroupCriterionResourceName = response.getResults(0).getResourceName(); System.out.printf( "Successfully created ad group criterion with resource name '%s' " + "targeting user list with resource name '%s' with ad group with ID %d.%n", adGroupCriterionResourceName, userList, adGroupId); return adGroupCriterionResourceName; } }
Example #22
Source File: GetGeoTargetConstantsByNames.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Runs the example. * * @param googleAdsClient the Google Ads API client. * @throws GoogleAdsException if an API request failed with one or more service errors. */ private void runExample(GoogleAdsClient googleAdsClient) { try (GeoTargetConstantServiceClient geoTargetClient = googleAdsClient.getLatestVersion().createGeoTargetConstantServiceClient()) { SuggestGeoTargetConstantsRequest.Builder requestBuilder = SuggestGeoTargetConstantsRequest.newBuilder(); // Locale is using ISO 639-1 format. If an invalid locale is given, 'en' is used by default. requestBuilder.setLocale(StringValue.of("en")); // A list of country codes can be referenced here: // https://developers.google.com/adwords/api/docs/appendix/geotargeting requestBuilder.setCountryCode(StringValue.of("FR")); requestBuilder .getLocationNamesBuilder() .addAllNames( Stream.of("Paris", "Quebec", "Spain", "Deutschland") .map(StringValue::of) .collect(Collectors.toList())); SuggestGeoTargetConstantsResponse response = geoTargetClient.suggestGeoTargetConstants(requestBuilder.build()); for (GeoTargetConstantSuggestion suggestion : response.getGeoTargetConstantSuggestionsList()) { System.out.printf( "%s (%s,%s,%s,%s) is found in locale (%s) with reach (%d) for search term (%s).%n", suggestion.getGeoTargetConstant().getResourceName(), suggestion.getGeoTargetConstant().getName().getValue(), suggestion.getGeoTargetConstant().getCountryCode().getValue(), suggestion.getGeoTargetConstant().getTargetType().getValue(), suggestion.getGeoTargetConstant().getStatus().name(), suggestion.getLocale().getValue(), suggestion.getReach().getValue(), suggestion.getSearchTerm().getValue()); } } }
Example #23
Source File: CreateCustomer.java From google-ads-java with Apache License 2.0 | 5 votes |
private void runExample(GoogleAdsClient googleAdsClient, Long managerId) { // Formats the current date/time to use as a timestamp in the new customer description. String dateTime = ZonedDateTime.now().format(DateTimeFormatter.RFC_1123_DATE_TIME); // Initializes a Customer object to be created. Customer customer = Customer.newBuilder() .setDescriptiveName( StringValue.of("Account created with CustomerService on '" + dateTime + "'")) .setCurrencyCode(StringValue.of("USD")) .setTimeZone(StringValue.of("America/New_York")) // Optional: Sets additional attributes of the customer. .setTrackingUrlTemplate(StringValue.of("{lpurl}?device={device}")) .setFinalUrlSuffix( StringValue.of("keyword={keyword}&matchtype={matchtype}&adgroupid={adgroupid}")) .setHasPartnersBadge(BoolValue.of(false)) .build(); // Sends the request to create the customer. try (CustomerServiceClient client = googleAdsClient.getLatestVersion().createCustomerServiceClient()) { CreateCustomerClientResponse response = client.createCustomerClient(managerId.toString(), customer); System.out.printf( "Created a customer with resource name '%s' under the manager account with" + " customer ID '%d'.%n", response.getResourceName(), managerId); } }
Example #24
Source File: AddDynamicPageFeed.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Updates a campaign to set the DSA feed. * * @param googleAdsClient the Google Ads API client. * @param customerId the customer ID. * @param feedResourceName the resource name of the feed. * @param campaignId the campaign ID of the campaign to update. */ private static void updateCampaignDsaSetting( GoogleAdsClient googleAdsClient, long customerId, String feedResourceName, long campaignId) { // Retrieves the existing dynamic search ads settings for the campaign. DynamicSearchAdsSetting dsaSetting = getDsaSetting(googleAdsClient, customerId, campaignId); dsaSetting.toBuilder().addAllFeeds(ImmutableList.of(StringValue.of(feedResourceName))).build(); // Creates the campaign object to update. Campaign campaign = Campaign.newBuilder() .setResourceName(ResourceNames.campaign(customerId, campaignId)) .setDynamicSearchAdsSetting(dsaSetting) .build(); // Creates the update operation and sets the update mask. CampaignOperation operation = CampaignOperation.newBuilder() .setUpdate(campaign) .setUpdateMask(FieldMasks.allSetFieldsOf(campaign)) .build(); // Creates the service client. try (CampaignServiceClient campaignServiceClient = googleAdsClient.getLatestVersion().createCampaignServiceClient()) { // Updates the campaign. MutateCampaignsResponse response = campaignServiceClient.mutateCampaigns( Long.toString(customerId), ImmutableList.of(operation)); // Displays the results. System.out.printf( "Updated campaign with resource name '%s'.%n", response.getResults(0).getResourceName()); } }
Example #25
Source File: AddCompleteCampaignsUsingMutateJob.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Builds new ad group criterion operations for creating keywords. 50% of keywords are created * with some invalid characters to demonstrate how MutateJobService returns information about such * errors. * * @param adGroupOperations the ad group operations to be used to create ad group criteria. * @return the ad group criterion operations. */ private List<AdGroupCriterionOperation> buildAdGroupCriterionOperations( List<AdGroupOperation> adGroupOperations) { List<AdGroupCriterionOperation> operations = new ArrayList<>(); for (AdGroupOperation adGroupOperation : adGroupOperations) { for (int i = 0; i < NUMBER_OF_KEYWORDS_TO_ADD; i++) { // Creates a keyword text by making 50% of keywords invalid to demonstrate error handling. String keywordText = "mars" + i; if (i % 2 == 0) { keywordText += "!!!"; } // Creates an ad group criterion using the created keyword text. AdGroupCriterion adGroupCriterion = AdGroupCriterion.newBuilder() .setKeyword( KeywordInfo.newBuilder() .setText(StringValue.of(keywordText)) .setMatchType(KeywordMatchType.BROAD) .build()) .setAdGroup(StringValue.of(adGroupOperation.getCreate().getResourceName())) .setStatus(AdGroupCriterionStatus.ENABLED) .build(); // Creates an ad group criterion operation and adds it to the operations list. AdGroupCriterionOperation op = AdGroupCriterionOperation.newBuilder().setCreate(adGroupCriterion).build(); operations.add(op); } } return operations; }
Example #26
Source File: AddConversionAction.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Runs the example. * * @param googleAdsClient the Google Ads API client. * @param customerId the client customer ID. * @throws GoogleAdsException if an API request failed with one or more service errors. */ private void runExample(GoogleAdsClient googleAdsClient, long customerId) { // Creates a ConversionAction. ConversionAction conversionAction = ConversionAction.newBuilder() .setName( StringValue.of("Earth to Mars Cruises Conversion #" + System.currentTimeMillis())) .setCategory(ConversionActionCategory.DEFAULT) .setType(ConversionActionType.WEBPAGE) .setStatus(ConversionActionStatus.ENABLED) .setViewThroughLookbackWindowDays(Int64Value.of(15L)) .setValueSettings( ValueSettings.newBuilder() .setDefaultValue(DoubleValue.of(23.41)) .setAlwaysUseDefaultValue(BoolValue.of(true)) .build()) .build(); // Creates the operation. ConversionActionOperation operation = ConversionActionOperation.newBuilder().setCreate(conversionAction).build(); try (ConversionActionServiceClient conversionActionServiceClient = googleAdsClient.getLatestVersion().createConversionActionServiceClient()) { MutateConversionActionsResponse response = conversionActionServiceClient.mutateConversionActions( Long.toString(customerId), Collections.singletonList(operation)); System.out.printf("Added %d conversion actions:%n", response.getResultsCount()); for (MutateConversionActionResult result : response.getResultsList()) { System.out.printf( "New conversion action added with resource name: '%s'%n", result.getResourceName()); } } }
Example #27
Source File: UpdateExpandedTextAd.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Runs the example. * * @param googleAdsClient the client to use for connecting to the API. * @param customerId the customer ID to update. * @param adId the ad ID to update. */ private void runExample(GoogleAdsClient googleAdsClient, long customerId, long adId) { // Creates an AdOperation to update an ad. AdOperation.Builder adOperation = AdOperation.newBuilder(); // Creates an Ad in the update field of the operation. Ad.Builder adBuilder = adOperation .getUpdateBuilder() .setResourceName(ResourceNames.ad(customerId, adId)) .addFinalUrls(StringValue.of("http://www.example.com/")) .addFinalMobileUrls(StringValue.of("http://www.example.com/mobile")); // Sets the expanded text ad properties to update on the ad. adBuilder .getExpandedTextAdBuilder() .setHeadlinePart1(StringValue.of("Cruise to Pluto #" + System.currentTimeMillis())) .setHeadlinePart2(StringValue.of("Tickets on sale now")) .setDescription(StringValue.of("Best space cruise ever.")); // Sets the update mask (the fields which will be modified) to be all the fields we set above. adOperation.setUpdateMask(FieldMasks.allSetFieldsOf(adBuilder.build())); // Creates a service client to connect to the API. try (AdServiceClient adServiceClient = googleAdsClient.getLatestVersion().createAdServiceClient()) { // Issues the mutate request. MutateAdsResponse response = adServiceClient.mutateAds( String.valueOf(customerId), ImmutableList.of(adOperation.build())); // Displays the result. for (MutateAdResult result : response.getResultsList()) { System.out.printf("Ad with resource name '%s' was updated.%n", result.getResourceName()); } } }
Example #28
Source File: AddHotelCallout.java From google-ads-java with Apache License 2.0 | 5 votes |
/** Creates a new extension feed item for the callout. */ private String addExtensionFeedItem( GoogleAdsClient googleAdsClient, long customerId, String calloutText, String languageCode) { // Creates the callout with text and language of choice. HotelCalloutFeedItem hotelCallout = HotelCalloutFeedItem.newBuilder() .setText(StringValue.of(calloutText)) .setLanguageCode(StringValue.of(languageCode)) .build(); // Attaches the callout to a feed item. ExtensionFeedItem feedItem = ExtensionFeedItem.newBuilder().setHotelCalloutFeedItem(hotelCallout).build(); // Creates the feed item operation. ExtensionFeedItemOperation feedItemOperation = ExtensionFeedItemOperation.newBuilder().setCreate(feedItem).build(); // Issues the create request to create the feed item. try (ExtensionFeedItemServiceClient extensionFeedItemServiceClient = googleAdsClient.getLatestVersion().createExtensionFeedItemServiceClient()) { MutateExtensionFeedItemsResponse response = extensionFeedItemServiceClient.mutateExtensionFeedItems( Long.toString(customerId), ImmutableList.of(feedItemOperation)); String extensionFeedItemResourceName = response.getResults(0).getResourceName(); System.out.printf( "Added a extension feed item with resource name: '%s'.%n", extensionFeedItemResourceName); return extensionFeedItemResourceName; } }
Example #29
Source File: AddKeywords.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Runs the example. * * @param googleAdsClient the Google Ads API client. * @param customerId the client customer ID. * @param adGroupId the ad group ID. * @param keywordText the keyword text to add. * @throws GoogleAdsException if an API request failed with one or more service errors. */ private void runExample( GoogleAdsClient googleAdsClient, long customerId, long adGroupId, String keywordText) { // Configures the keywordText text and match type settings. KeywordInfo keywordInfo = KeywordInfo.newBuilder() .setText(StringValue.of(keywordText)) .setMatchType(KeywordMatchType.EXACT) .build(); String adGroupResourceName = ResourceNames.adGroup(customerId, adGroupId); // Constructs an ad group criterion using the keywordText configuration above. AdGroupCriterion criterion = AdGroupCriterion.newBuilder() .setAdGroup(StringValue.of(adGroupResourceName)) .setStatus(AdGroupCriterionStatus.ENABLED) .setKeyword(keywordInfo) .build(); AdGroupCriterionOperation op = AdGroupCriterionOperation.newBuilder().setCreate(criterion).build(); try (AdGroupCriterionServiceClient agcServiceClient = googleAdsClient.getLatestVersion().createAdGroupCriterionServiceClient()) { MutateAdGroupCriteriaResponse response = agcServiceClient.mutateAdGroupCriteria(Long.toString(customerId), ImmutableList.of(op)); System.out.printf("Added %d ad group criteria:%n", response.getResultsCount()); for (MutateAdGroupCriterionResult result : response.getResultsList()) { System.out.println(result.getResourceName()); } } }
Example #30
Source File: UpdateSitelink.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Runs the example. * * @param googleAdsClient the Google Ads API client. * @param customerId the client customer ID. * @param feedItemId the ID of the feed item to update. * @param sitelinkText the new sitelink text to update to. * @throws GoogleAdsException if an API request failed with one or more service errors. */ private void runExample( GoogleAdsClient googleAdsClient, long customerId, long feedItemId, String sitelinkText) { try (ExtensionFeedItemServiceClient extensionFeedItemServiceClient = googleAdsClient.getLatestVersion().createExtensionFeedItemServiceClient()) { // Creates an extension feed item using the specified feed item ID and sitelink text. ExtensionFeedItem extensionFeedItem = ExtensionFeedItem.newBuilder() .setResourceName(ResourceNames.extensionFeedItem(customerId, feedItemId)) .setSitelinkFeedItem( SitelinkFeedItem.newBuilder().setLinkText(StringValue.of(sitelinkText)).build()) .build(); // Constructs an operation that will update the extension feed item, using the FieldMasks // utility to derive the update mask. This mask tells the Google Ads API which attributes of // the extension feed item you want to change. ExtensionFeedItemOperation operation = ExtensionFeedItemOperation.newBuilder() .setUpdate(extensionFeedItem) .setUpdateMask(FieldMasks.allSetFieldsOf(extensionFeedItem)) .build(); // Sends the operation in a mutate request. MutateExtensionFeedItemsResponse response = extensionFeedItemServiceClient.mutateExtensionFeedItems( Long.toString(customerId), ImmutableList.of(operation)); // Prints the resource name of each updated object. for (MutateExtensionFeedItemResult mutateExtensionFeedItemResult : response.getResultsList()) { System.out.printf( "Updated extension feed item with the resource name: '%s'.%n", mutateExtensionFeedItemResult.getResourceName()); } } }