Skorzystaj z FeedItemService
, aby wypełnić obecne obiekty Feed
obiektami FeedItem
, które są podobne do wierszy bazy danych. Każdy element FeedItem
jest pojedynczym wierszem i zawiera wiele elementów FeedItemAttributeValue
. Każda wartość FeedItemAttributeValue
to dane, które odpowiadają konkretnemu atrybutowi (kolumna) w pliku danych (tabeli) tego elementu (wiersza). Kiedy wypełniamy elementy kanału, zasadniczo dodajemy tylko wiersze z danymi do istniejącej tabeli.
Będziemy potrzebować identyfikatorów atrybutów pobranych z pliku danych utworzonego w ostatnim kroku. Każdy FeedItemAttributeValue
w obrębie FeedItem
musi mieć określony identyfikator atrybutu, aby wskazać systemowi, który atrybut (kolumna) odpowiada, a każdy FeedItem
może mieć maksymalnie FeedItemAttributeValue
z tym identyfikatorem.
Upewnij się, że mapujesz właściwe identyfikatory atrybutów do odpowiednich danych. Śledzenie może być dość trudne, dlatego tworzenie struktury do przechowywania identyfikatorów atrybutów kanału z jakimś identyfikatorem jest często przydatna.
Z odpowiedzi na końcu pobieramy identyfikatory elementów kanału do wykorzystania w późniejszym kroku. Jeśli nie chcesz dopasowywać określonych elementów z pliku danych, możesz pominąć ten krok.
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}