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.
withResourceNames AdsApp.MediaSelector Restricts this selector to return only media with the given Google Ads API resource names.

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("media_file.file_size") - orders results by media_file.file_size, in ascending order.
  • orderBy("media_file.mime_type ASC") - orders results by media_file.mime_type, in ascending order.
  • orderBy("media_file.name DESC") - orders results by media_file.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("media_file.name ASC")
                   .orderBy("media_file.file_size DESC");

The results will be ordered by media_file.name in ascending order. Results with equal media_file.name values will be ordered by media_file.file_size 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("metrics.clicks > 5")
    .withCondition("metrics.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. metrics.impressions, metrics.clicks):
    <  <=  >  >=  =  !=
  • For Double columns (e.g. metrics.ctr):
    <  >
  • For String columns (e.g. Name):
    =  !=  (NOT) (LIKE | CONTAINS | REGEXP_MATCH)
  • 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)")

Columns

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

Column Type Example
Media attributes
media_file.file_size Long withCondition("media_file.file_size > 4000"). The value is in bytes.
media_file.mime_type String withCondition("media_file.mime_type = 'IMAGE_PNG'")
media_file.name String withCondition("media_file.name REGEXP_MATCH '.*shoes.*'")
media_file.id Long withCondition("media_file.id = 123")
media_file.source_url String withCondition("media_file.source_url CONTAINS 'example.png'")
media_file.type Enumeration: AUDIO, DYNAMIC_IMAGE, ICON, IMAGE, STANDARD_ICON, VIDEO, COMPOSITE_BUNDLE withCondition("media_file.type = IMAGE")
media_file.video.youtube_video_id String withCondition("media_file.video.youtube_video_id = '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 Object[] 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.

withResourceNames(resourceNames)

Restricts this selector to return only media with the given Google Ads API resource names.
const mediaResourceNames = [
  'customers/1234567890/mediaFiles/111',
  'customers/1234567890/mediaFiles/222',
  'customers/1234567890/mediaFiles/333',
];
selector = selector.withResourceNames(mediaResourceNames);

The resulting selector can be further refined by applying additional conditions to it. The resource name condition will then be AND-ed together with all the other conditions.

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

Arguments:

NameTypeDescription
resourceNames String[] Array of media resource names.

Return values:

TypeDescription
AdsApp.MediaSelector The selector restricted to the given resource names.