フィード アイテム

FeedItemService を使用して、既存の FeedFeedItem オブジェクトを入力します。これは、データベース行に似ています。各 FeedItem は単一の行であり、複数の FeedItemAttributeValue を含みます。各 FeedItemAttributeValue は、このフィード アイテム(行)のフィード(表)の特定のフィード属性(列)に対応するデータです。フィード アイテムの入力時には、基本的にはデータが含まれる行を既存のテーブルに追加するだけです。

最後の手順で作成したフィードから取得した属性 ID が必要です。FeedItem 内の各 FeedItemAttributeValue は、対応する属性(列)をシステムに伝えるために属性 ID を指定する必要があります。各 FeedItem は特定の属性 ID を持つ FeedItemAttributeValue しか持てません。

正しいフィード属性 ID を正しいデータにマッピングしてください。追跡が難しいため、フィード属性 ID をなんらかの識別子と保存する構造を構築すると役に立つことがよくあります。

レスポンスからフィード アイテム ID を後で取得するために取得しますが、特定のフィード アイテムと一致しない場合は、このステップを省略できます。

Ruby

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

data = {
  feed: feed_resource_name,
  # The attribute IDs come back in the same order that they were added.
  link_text_attribute_id: attribute_ids[0],
  final_url_attribute_id: attribute_ids[1],
  line_1_attribute_id: attribute_ids[2],
  line_2_attribute_id: attribute_ids[3],
}

def new_feed_item_operation(client, data, text, final_url, line_1, line_2)
  feed_item = client.resource.feed_item do |fi|
    fi.feed = data[:feed]

    fi.attribute_values << client.resource.feed_item_attribute_value do |av|
      av.feed_attribute_id = data[:link_text_attribute_id]
      av.string_value = text
    end
    fi.attribute_values << client.resource.feed_item_attribute_value do |av|
      av.feed_attribute_id = data[:final_url_attribute_id]
      av.string_values << final_url
    end
    fi.attribute_values << client.resource.feed_item_attribute_value do |av|
      av.feed_attribute_id = data[:line_1_attribute_id]
      av.string_value = line_1
    end
    fi.attribute_values << client.resource.feed_item_attribute_value do |av|
      av.feed_attribute_id = data[:line_2_attribute_id]
      av.string_value = line_2
    end
  end

  client.operation.create_resource.feed_item(feed_item)
end

operations = []
operations << new_feed_item_operation(client, data, "Home", "http://www.example.com", "Home line 1", "Home line 2")
operations << new_feed_item_operation(client, data, "Stores", "http://www.example.com/stores", "Stores line 1", "Stores line 2")
operations << new_feed_item_operation(client, data, "On Sale", "http://www.example.com/sale", "On Sale line 1", "On Sale line 2")
operations << new_feed_item_operation(client, data, "Support", "http://www.example.com/support", "Support line 1", "Support line 2")
operations << new_feed_item_operation(client, data, "Products", "http://www.example.com/catalogue", "Products line 1", "Products line 2")
operations << new_feed_item_operation(client, data, "About Us", "http://www.example.com/about", "About Us line 1", "About Us line 2")

response = client.service.feed_item.mutate_feed_items(customer_id, operations)

# We will need the resource name of the feed item to use in targeting.
feed_items = response.results.map {|result| result.resource_name}
# We may also need the feed item ID if we are going to use it in a mapping function.
# For feed items, the ID is the last part of the resource name, after the '~'.
feed_item_ids = feed_items.map do {|feed_item| resource_name.split('~').last}