AdsApp.​MediaSelector

Fetches media in an account.

Typical usage:

 var mediaIterator = AdsApp.adMedia().media()
   .withCondition("Type = IMAGE")
   .get();

Methods:

MemberTypeDescription
get AdsApp.MediaIterator Fetches the requested media and returns an iterator.
orderBy AdsApp.MediaSelector Specifies the ordering of the resulting entities.
withCondition AdsApp.MediaSelector Adds the specified condition to the selector in order to narrow down the results.
withIds AdsApp.MediaSelector Restricts this selector to return only media with the given media IDs.
withLimit AdsApp.MediaSelector Specifies limit for the selector to use.

get()

Fetches the requested media and returns an iterator.

Return values:

TypeDescription
AdsApp.MediaIterator Iterator of the requested media.

orderBy(orderBy)

Specifies the ordering of the resulting entities. orderBy parameter can have one of the following forms:
  • orderBy("FileSize") - orders results by FileSize, in ascending order.
  • orderBy("MimeType ASC") - orders results by MimeType, in ascending order.
  • orderBy("Name DESC") - orders results by Name, in descending order.

See MediaSelector.withCondition(String) for enumeration of columns that can be used.

orderBy() may be called multiple times. Consider the following example:

 selector = selector.orderBy("Name ASC").orderBy("FileSize DESC");

The results will be ordered by Name in ascending order. Results with equal Name values will be ordered by FileSize in descending order.

Arguments:

NameTypeDescription
orderBy String Ordering to apply.

Return values:

TypeDescription
AdsApp.MediaSelector The selector with ordering applied.

withCondition(condition)

Adds the specified condition to the selector in order to narrow down the results.

Multiple conditions may be added to the same selector:

 selector = selector.withCondition("Clicks > 5").withCondition("Impressions > 100");
All specified conditions are AND-ed together. The above example will retrieve entities that observed over 100 impressions AND more than 5 clicks.

The parameter to be passed into this method must be of the following form:

 "COLUMN_NAME OPERATOR VALUE"

Operators

The operator that can be used in a condition depends on the type of column.
  • For Integer and Long columns (e.g. Impressions, Clicks):
    <  <=  >  >=  =  !=
  • For Double columns (e.g. Ctr):
    <  >
  • For String columns (e.g. Name):
    =  !=  STARTS_WITH  STARTS_WITH_IGNORE_CASE  CONTAINS
     CONTAINS_IGNORE_CASE  DOES_NOT_CONTAIN  DOES_NOT_CONTAIN_IGNORE_CASE
  • For Enumeration columns (ones that can only take one value from a predefined list, such as Status):
    =  !=  IN []  NOT_IN []
  • For StringSet columns (e.g. LabelNames):
    CONTAINS_ALL []  CONTAINS_ANY []  CONTAINS_NONE []
Conditions using IN, NOT_IN, CONTAINS_ALL, CONTAINS_ANY and CONTAINS_NONE operators look as follows:
 withCondition("ColumnName IN [Value1, Value2]")
Operators are case-sensitive: starts_with won't work.

Columns

All column names are case-sensitive, and so are all values of enumerated columns (such as Status).

Column Type Example
Media attributes
FileSize Long withCondition("FileSize > 4000"). The value is in bytes.
MimeType String withCondition("MimeType = 'IMAGE_PNG'")
Name String withCondition("Name CONTAINS_IGNORE_CASE 'shoes'")
ReferenceId Long withCondition("ReferenceId = 123")
SourceUrl String withCondition("SourceUrl CONTAINS 'example.png'")
Type Enumeration: AUDIO, DYNAMIC_IMAGE, ICON, IMAGE, STANDARD_ICON, VIDEO, COMPOSITE_BUNDLE withCondition("Type = IMAGE")
YouTubeVideoId String withCondition("YouTubeVideoId = 'vPqslcwZ8Kk'")

Arguments:

NameTypeDescription
condition String Condition to add to the selector.

Return values:

TypeDescription
AdsApp.MediaSelector The selector with the condition applied.

withIds(ids)

Restricts this selector to return only media with the given media IDs.
 var mediaIds = [12345, 23456, 34567];
 selector = selector.withIds(mediaIds);

The resulting selector can be further refined by applying additional conditions to it. The ID-based condition will then be AND-ed together with all the other conditions, including any other ID-based conditions. So, for instance, the following selector:

 AdsApp.adMedia().media()
    .withIds([12345, 23456, 34567])
    .withIds([34567, 45678, 56789]);
will only get the media with ID 34567, since it would be the only media that satisfies both ID conditions.

The selector can only support up to 10,000 IDs. If more than 10,000 IDs are specified, the corresponding get() call will fail with a runtime error.

Arguments:

NameTypeDescription
ids long[] Array of media IDs.

Return values:

TypeDescription
AdsApp.MediaSelector The selector restricted to the given IDs.

withLimit(limit)

Specifies limit for the selector to use. For instance, withLimit(50) returns only the first 50 entities.

Arguments:

NameTypeDescription
limit int How many entities to return.

Return values:

TypeDescription
AdsApp.MediaSelector The selector with limit applied.