Class: Zernio::AdLibraryApi

Inherits:
Object
  • Object
show all
Defined in:
lib/zernio-sdk/api/ad_library_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ AdLibraryApi

Returns a new instance of AdLibraryApi.



19
20
21
# File 'lib/zernio-sdk/api/ad_library_api.rb', line 19

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



17
18
19
# File 'lib/zernio-sdk/api/ad_library_api.rb', line 17

def api_client
  @api_client
end

Instance Method Details

#search_ad_library(opts = {}) ⇒ SearchAdLibrary200Response

Search the public Ad Library Competitor and market research over the public ad archives. Meta's Ad Library (GET /ads_archive) is searched with Zernio's own developer access, so platform=meta needs no connected account at all. LinkedIn's Ad Library (GET /rest/adLibrary) runs on a connected linkedin / linkedinads account, passed as accountId. Passing a Meta account as accountId also selects Meta. Rows are returned in the platform's raw shape under data; paging.after is an opaque cursor on both (null when exhausted). Meta coverage. Political and social-issue ads are searchable worldwide. Every other ad is in the archive only if it was delivered to the EU or UK within the last year, so a US-only commercial advertiser is invisible. Spend, impressions and demographics are political-only fields and are left out of the default projection; request them via fields. All customers share Zernio's Meta quota, so a 429 means back off for a minute. LinkedIn coverage. Ads served after June 1 2023, worldwide, kept for a year after their last impression. EU-delivered ads carry impression ranges and the disclosed targeting facets. Pages are capped at 25 ads (limit > 25 is a 400); after is the next offset. Which params apply: q, countries, limit, after on both; pageIds, adType, status, platforms, mediaType, languages, searchType, fields, since, until are Meta-only; advertiser is LinkedIn-only. Passing a param the account's platform does not support is a 400 naming the param.

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :platform (String)

    Which archive to search. `meta` needs no accountId. Required unless accountId is given.

  • :account_id (String)

    Zernio SocialAccount id. Required for LinkedIn (linkedin / linkedinads: its token searches). Optional for Meta, where any facebook / instagram / metaads account only selects the platform.

  • :q (String)

    Keyword search. Meta does not translate it, so write it in the ads' language. Required unless pageIds (Meta) or advertiser (LinkedIn) is given.

  • :page_ids (String)

    Meta only. Comma-separated Facebook Page ids (max 10) whose ads to list.

  • :advertiser (String)

    LinkedIn only. Advertiser (Page) name to search.

  • :countries (String)

    Comma-separated ISO 3166-1 alpha-2 codes the ads reached. Meta defaults to ALL (an explicit ALL is Meta-only); LinkedIn searches every market when omitted.

  • :ad_type (String)

    Meta only. (default to 'ALL')

  • :status (String)

    Meta only. ACTIVE = eligible for delivery right now. (default to 'ACTIVE')

  • :platforms (String)

    Meta only. Comma-separated publisher platforms: FACEBOOK, INSTAGRAM, AUDIENCE_NETWORK, MESSENGER, WHATSAPP, OCULUS, THREADS, STREAMING_SERVICES.

  • :media_type (String)

    Meta only.

  • :languages (String)

    Meta only. Comma-separated ISO 639-1 codes of the ad text.

  • :since (Date)

    Meta only. Earliest delivery date (YYYY-MM-DD). LinkedIn's archive does not filter by date, so it is a 400 there: filter on details.adStatistics.firstImpressionAt / latestImpressionAt instead (EU-delivered ads only).

  • :_until (Date)

    Meta only. Latest delivery date (YYYY-MM-DD); a 400 on LinkedIn, see since.

  • :search_type (String)

    Meta only. Whether q matches words in any order or as an exact phrase (comma-separate phrases to match all of them). (default to 'KEYWORD_UNORDERED')

  • :fields (String)

    Meta only. Comma-separated Graph field override. Supports nested {} projections and Graph field modifiers, so a nested edge can be paged explicitly: without a .limit() modifier the expansion runs at the Meta default page size and the tail is dropped silently.

  • :limit (Integer)

    Rows per page. LinkedIn accepts at most 25. (default to 25)

  • :after (String)

    paging.after of the previous page.

Returns:



43
44
45
46
# File 'lib/zernio-sdk/api/ad_library_api.rb', line 43

def search_ad_library(opts = {})
  data, _status_code, _headers = search_ad_library_with_http_info(opts)
  data
end

#search_ad_library_with_http_info(opts = {}) ⇒ Array<(SearchAdLibrary200Response, Integer, Hash)>

Search the public Ad Library Competitor and market research over the public ad archives. Meta's Ad Library (`GET /ads_archive`) is searched with Zernio's own developer access, so `platform=meta` needs no connected account at all. LinkedIn's Ad Library (`GET /rest/adLibrary`) runs on a connected `linkedin` / `linkedinads` account, passed as `accountId`. Passing a Meta account as `accountId` also selects Meta. Rows are returned in the platform's raw shape under `data`; `paging.after` is an opaque cursor on both (`null` when exhausted). Meta coverage. Political and social-issue ads are searchable worldwide. Every other ad is in the archive only if it was delivered to the EU or UK within the last year, so a US-only commercial advertiser is invisible. Spend, impressions and demographics are political-only fields and are left out of the default projection; request them via `fields`. All customers share Zernio's Meta quota, so a `429` means back off for a minute. LinkedIn coverage. Ads served after June 1 2023, worldwide, kept for a year after their last impression. EU-delivered ads carry impression ranges and the disclosed targeting facets. Pages are capped at 25 ads (`limit` > 25 is a 400); `after` is the next offset. Which params apply: `q`, `countries`, `limit`, `after` on both; `pageIds`, `adType`, `status`, `platforms`, `mediaType`, `languages`, `searchType`, `fields`, `since`, `until` are Meta-only; `advertiser` is LinkedIn-only. Passing a param the account's platform does not support is a 400 naming the param.

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :platform (String)

    Which archive to search. `meta` needs no accountId. Required unless accountId is given.

  • :account_id (String)

    Zernio SocialAccount id. Required for LinkedIn (linkedin / linkedinads: its token searches). Optional for Meta, where any facebook / instagram / metaads account only selects the platform.

  • :q (String)

    Keyword search. Meta does not translate it, so write it in the ads' language. Required unless pageIds (Meta) or advertiser (LinkedIn) is given.

  • :page_ids (String)

    Meta only. Comma-separated Facebook Page ids (max 10) whose ads to list.

  • :advertiser (String)

    LinkedIn only. Advertiser (Page) name to search.

  • :countries (String)

    Comma-separated ISO 3166-1 alpha-2 codes the ads reached. Meta defaults to ALL (an explicit ALL is Meta-only); LinkedIn searches every market when omitted.

  • :ad_type (String)

    Meta only. (default to 'ALL')

  • :status (String)

    Meta only. ACTIVE = eligible for delivery right now. (default to 'ACTIVE')

  • :platforms (String)

    Meta only. Comma-separated publisher platforms: FACEBOOK, INSTAGRAM, AUDIENCE_NETWORK, MESSENGER, WHATSAPP, OCULUS, THREADS, STREAMING_SERVICES.

  • :media_type (String)

    Meta only.

  • :languages (String)

    Meta only. Comma-separated ISO 639-1 codes of the ad text.

  • :since (Date)

    Meta only. Earliest delivery date (YYYY-MM-DD). LinkedIn's archive does not filter by date, so it is a 400 there: filter on details.adStatistics.firstImpressionAt / latestImpressionAt instead (EU-delivered ads only).

  • :_until (Date)

    Meta only. Latest delivery date (YYYY-MM-DD); a 400 on LinkedIn, see since.

  • :search_type (String)

    Meta only. Whether q matches words in any order or as an exact phrase (comma-separate phrases to match all of them). (default to 'KEYWORD_UNORDERED')

  • :fields (String)

    Meta only. Comma-separated Graph field override. Supports nested {} projections and Graph field modifiers, so a nested edge can be paged explicitly: without a .limit() modifier the expansion runs at the Meta default page size and the tail is dropped silently.

  • :limit (Integer)

    Rows per page. LinkedIn accepts at most 25. (default to 25)

  • :after (String)

    paging.after of the previous page.

Returns:

  • (Array<(SearchAdLibrary200Response, Integer, Hash)>)

    SearchAdLibrary200Response data, response status code and response headers



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/zernio-sdk/api/ad_library_api.rb', line 69

def search_ad_library_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: AdLibraryApi.search_ad_library ...'
  end
  allowable_values = ["meta", "linkedin"]
  if @api_client.config.client_side_validation && opts[:'platform'] && !allowable_values.include?(opts[:'platform'])
    fail ArgumentError, "invalid value for \"platform\", must be one of #{allowable_values}"
  end
  if @api_client.config.client_side_validation && !opts[:'q'].nil? && opts[:'q'].to_s.length > 100
    fail ArgumentError, 'invalid value for "opts[:"q"]" when calling AdLibraryApi.search_ad_library, the character length must be smaller than or equal to 100.'
  end

  if @api_client.config.client_side_validation && !opts[:'advertiser'].nil? && opts[:'advertiser'].to_s.length > 100
    fail ArgumentError, 'invalid value for "opts[:"advertiser"]" when calling AdLibraryApi.search_ad_library, the character length must be smaller than or equal to 100.'
  end

  allowable_values = ["ALL", "POLITICAL_AND_ISSUE_ADS", "HOUSING_ADS", "EMPLOYMENT_ADS", "FINANCIAL_PRODUCTS_AND_SERVICES_ADS"]
  if @api_client.config.client_side_validation && opts[:'ad_type'] && !allowable_values.include?(opts[:'ad_type'])
    fail ArgumentError, "invalid value for \"ad_type\", must be one of #{allowable_values}"
  end
  allowable_values = ["ACTIVE", "INACTIVE", "ALL"]
  if @api_client.config.client_side_validation && opts[:'status'] && !allowable_values.include?(opts[:'status'])
    fail ArgumentError, "invalid value for \"status\", must be one of #{allowable_values}"
  end
  allowable_values = ["ALL", "IMAGE", "MEME", "VIDEO", "NONE"]
  if @api_client.config.client_side_validation && opts[:'media_type'] && !allowable_values.include?(opts[:'media_type'])
    fail ArgumentError, "invalid value for \"media_type\", must be one of #{allowable_values}"
  end
  allowable_values = ["KEYWORD_UNORDERED", "KEYWORD_EXACT_PHRASE"]
  if @api_client.config.client_side_validation && opts[:'search_type'] && !allowable_values.include?(opts[:'search_type'])
    fail ArgumentError, "invalid value for \"search_type\", must be one of #{allowable_values}"
  end
  if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] > 100
    fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling AdLibraryApi.search_ad_library, must be smaller than or equal to 100.'
  end

  if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] < 1
    fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling AdLibraryApi.search_ad_library, must be greater than or equal to 1.'
  end

  # resource path
  local_var_path = '/v1/ads/library'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'platform'] = opts[:'platform'] if !opts[:'platform'].nil?
  query_params[:'accountId'] = opts[:'account_id'] if !opts[:'account_id'].nil?
  query_params[:'q'] = opts[:'q'] if !opts[:'q'].nil?
  query_params[:'pageIds'] = opts[:'page_ids'] if !opts[:'page_ids'].nil?
  query_params[:'advertiser'] = opts[:'advertiser'] if !opts[:'advertiser'].nil?
  query_params[:'countries'] = opts[:'countries'] if !opts[:'countries'].nil?
  query_params[:'adType'] = opts[:'ad_type'] if !opts[:'ad_type'].nil?
  query_params[:'status'] = opts[:'status'] if !opts[:'status'].nil?
  query_params[:'platforms'] = opts[:'platforms'] if !opts[:'platforms'].nil?
  query_params[:'mediaType'] = opts[:'media_type'] if !opts[:'media_type'].nil?
  query_params[:'languages'] = opts[:'languages'] if !opts[:'languages'].nil?
  query_params[:'since'] = opts[:'since'] if !opts[:'since'].nil?
  query_params[:'until'] = opts[:'_until'] if !opts[:'_until'].nil?
  query_params[:'searchType'] = opts[:'search_type'] if !opts[:'search_type'].nil?
  query_params[:'fields'] = opts[:'fields'] if !opts[:'fields'].nil?
  query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
  query_params[:'after'] = opts[:'after'] if !opts[:'after'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'SearchAdLibrary200Response'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['bearerAuth']

  new_options = opts.merge(
    :operation => :"AdLibraryApi.search_ad_library",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: AdLibraryApi#search_ad_library\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end