Wednesday, 23 November 2016

Is there a way to get final urls for each keyword from api

Hi All,

I recently met an issue with final urls, I tried to get final urls for each keyword but it always return null for some reason, could you please help me with this issue ? Thanks a lot.



public class FinalUrls {

private static final int PAGE_SIZE = 100;

public static void main(String[] args) throws Exception {
// Generate a refreshable OAuth2 credential.
Credential oAuth2Credential = new OfflineCredentials.Builder()
.forApi(OfflineCredentials.Api.ADWORDS)
.fromFile()
.build()
.generateCredential();

// Construct an AdWordsSession.
AdWordsSession session = new AdWordsSession.Builder()
.fromFile()
.withOAuth2Credential(oAuth2Credential)
.build();

Long adGroupId = Long.parseLong("3310344562");

AdWordsServices adWordsServices = new AdWordsServices();

getFinalUrls(adWordsServices, session, adGroupId);
}

public static void getFinalUrls(AdWordsServices adWordsServices, AdWordsSession session, Long adGroupId) throws Exception {

int offset = 0;

// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface adGroupCriterionService =
adWordsServices.get(session, AdGroupCriterionServiceInterface.class);

SelectorBuilder builder = new SelectorBuilder();
Selector selector = builder
.fields(
AdGroupCriterionField.Id,
AdGroupCriterionField.CriteriaType,
AdGroupCriterionField.KeywordMatchType,
AdGroupCriterionField.KeywordText,
AdGroupCriterionField.FinalUrls)
.orderAscBy(AdGroupCriterionField.KeywordText)
.offset(offset)
.limit(PAGE_SIZE)
.in(AdGroupCriterionField.AdGroupId, adGroupId.toString())
.in(AdGroupCriterionField.CriteriaType, "KEYWORD")
.build();

AdGroupCriterionPage page = adGroupCriterionService.get(selector);

// Display ad group criteria.
if (page.getEntries() != null && page.getEntries().length > 0) {
// Display results.
for (AdGroupCriterion adGroupCriterionResult : page.getEntries()) {
Keyword keyword = (Keyword) adGroupCriterionResult.getCriterion();
System.out.printf(
"Keyword with text '%s', match type '%s', criteria type '%s', and ID %d was found.%n",
keyword.getText(), keyword.getMatchType(), keyword.getType(), keyword.getId());
BiddableAdGroupCriterion biddableAdGroupCriterion= (BiddableAdGroupCriterion) adGroupCriterionResult;
System.out.printf("Keyword final url is %s", bac.getBidModifier());
if (biddableAdGroupCriterion == null) {
System.out.println("object is null");
} else {
System.out.printf("Keyword final url is %s", biddableAdGroupCriterion.getFinalUrls().getUrls(0));
System.out.println();
}
}
} else {
System.out.println("No ad group criteria were found.");
}

offset += PAGE_SIZE;
selector = builder.increaseOffsetBy(PAGE_SIZE).build();
}
}

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups "AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/9f277c5a-3798-4059-970d-d1fff643951d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment