フィード

FeedService を使用して、アップロードするデータの形状を記述する Feed を作成します。フィードはデータベース テーブルに類似しており、データベース列として機能する複数の FeedAttribute を含めることができます。各属性には名前とタイプがあります。

以下の例ではサイトリンクのデータを作成するため、以下を指定する必要があります。

  • リンクテキスト
  • 最終ページ URL をリンクする
  • 行 1
  • 行 2

最終的にレンダリングされたサイトリンクでは、リンク自体に加えて 2 行の説明が表示されます。

USER のフィード origin を指定して、Google 広告が自動的に入力するのではなく、ユーザーデータによってフィードが入力されるようにします。

関連するすべての属性 ID を取得するには、作成後に完全なフィードを取得することが重要です。これは、次のステップでフィード アイテムを作成するときに正しい属性にデータを入力するために必要です。

Ruby

client = Google::Ads::GoogleAds::GoogleAdsClient.new

feed = client.resource.feed do |f|
  f.name = "example feed"
  f.origin = :USER

  # Specify the column name and data type. This is just raw data at this point,
  # and not yet linked to any particular purpose. The names are used to help us
  # remember what they are intended for later.
  f.attributes << client.resource.feed_attribute do |fa|
    fa.name = "Link Text"
    fa.type = :STRING
  end
  f.attributes << client.resource.feed_attribute do |fa|
    fa.name = "Link Final URL"
    fa.type = :URL_LIST
  end
  f.attributes << client.resource.feed_attribute do |fa|
    fa.name = "Line 1"
    fa.type = :STRING
  end
  f.attributes << client.resource.feed_attribute do |fa|
    fa.name = "Line 2"
    fa.type = :STRING
  end
end

operation = client.operation.create_resource.feed(feed)

feed_resource_name =
    client.service.feed.mutate_feeds(customer_id, [operation]).results.first.resource_name

# After we create the feed, we need to fetch it so we can determine the
# attribute IDs, which will be required when populating feed items.
feed = client.service.google_ads.search(
  customer_id,
  "select feed.attributes from feed where feed.resource_name = '#{feed_resource_name}'"
).first.feed

attribute_ids = feed.attributes.map {|attribute| attribute.id}