0

我正在构建一个与 Google Ad Manager API 交互的 rails 5 API,我需要一种方法来检索公司列表(也称为广告商),以便我可以使用它们来创建新订单并最终创建订单项。

我无法在 Ad Manager 文档中找到它,对于 ruby​​ 和其他语言都没有。

我还没有任何代码,因为我不知道要使用什么服务。

我希望有一系列广告客户:[{:name => 'Company 1', :id => '1234'}, {:name => 'Company 2', :id => '4321'}]

任何帮助将非常感激。我无法在 Ad Manager 文档中找到它,对于 ruby​​ 和其他语言都没有。

提前致谢!

4

1 回答 1

0

我找到了答案。我错了,它是 Ruby 示例的一部分:

def get_advertisers(ad_manager)
  company_service = ad_manager.service(:CompanyService, API_VERSION)

  # Create a statement to select companies.
  statement = ad_manager.new_statement_builder do |sb|
    sb.where = 'type = :type'
    sb.with_bind_variable('type', 'ADVERTISER')
  end

  # Retrieve a small amount of companies at a time, paging
  # through until all companies have been retrieved.
  page = {:total_result_set_size => 0}
  begin
    # Get the companies by statement.
    page = company_service.get_companies_by_statement(
        statement.to_statement()
    )

    # Print out some information for each company.
    unless page[:results].nil?
      page[:results].each_with_index do |company, index|
        puts '%d) Company with ID %d, name "%s", and type "%s" was found.' %
            [index + statement.offset, company[:id], company[:name],
            company[:type]]
      end
    end

    # Increase the statement offset by the page size to get the next page.
    statement.offset += statement.limit
  end while statement.offset < page[:total_result_set_size]

  puts 'Total number of companies: %d' % page[:total_result_set_size]
end
于 2019-01-25T17:09:52.943 回答