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();
}
}