When is it necessary to append fields to the Selector builder object?

42 views
Skip to first unread message

Aditya

unread,
Apr 7, 2015, 7:33:10 PM4/7/15
to adwor...@googlegroups.com
For instance, I'm just playing around with the example GetCampaigns.java code to try to understand it better.

Selector selector = builder.fields("Id", "Name").orderAscBy("Name").offset(offset).limit(PAGE_SIZE).build();

That segment is straight from the example code. To my understanding, the fields method basically selects the "Id" and "Name" fields to be returned. This is the basic/correct result (where both Id and Name are selected) - "Campaign with name "Campaign #1" and id "276202509" was found."

If I get rid of the "id" part and make it builder.fields("Name").orderAsc... , I see this result (the same, correct result, even though the fields() call was different:

Campaign with name "Campaign #1" and id "276202509" was found.

But if I use builder.fields("Id").orderAsc.... 

Campaign with name "null" and id "276202509" was found.

Does anyone know what might be going on here? If I build the selector based on just "name", it is still able to retrieve both name and Id. But if I retrieve based on just "id", then it seems it only finds the Id when asked (I feel like this should be expected behavior). Is "id" special somehow that we can access it even if we don't include it in our fields() call?



Anash P. Oommen (AdWords API Team)

unread,
Apr 8, 2015, 10:45:48 AM4/8/15
to adwor...@googlegroups.com
Hi Aditya,

There are a few required fields (e.g. IDs, Type fields for polymorphic types, etc.) that are returned by default, but my advise is not to depend on this behavior in your code. Request the fields you require explicitly in a selector, so that your code is proofed against changes in AdWords. 

Cheers,
Anash P. Oommen,
AdWords API Advisor.
Reply all
Reply to author
Forward
0 new messages