ข้อเท็จจริง

factories มีอินเทอร์เฟซระดับสูงสำหรับการสร้างการดำเนินการและทรัพยากร ด้วยไลบรารีของไคลเอ็นต์

ระบบจะสร้างเมธอดโรงงานสำหรับทรัพยากร, enum, การดำเนินการ และประเภทบริการจาก Google Ads API

การดำเนินการ

ไลบรารีจะมี client.operation.create_resource.<resource_type> client.operation.update_resource.<resource_type> และ client.operation.remove_resource.<resource_type> สร้างการดำเนินการเพื่อทำงานกับ Google Ads API ได้อย่างง่ายดาย

ตัวอย่างการสร้างทรัพยากรมีดังนี้

campaign_budget_operation = client.operation.create_resource.campaign_budget do |cb|
  cb.name = "Interplanetary Budget #{(Time.new.to_f * 1000).to_i}"

  cb.delivery_method = :STANDARD
  cb.amount_micros = 500000
end

return_budget = client.service.campaign_budget.mutate_campaign_budgets(
  customer_id,
  [campaign_budget_operation]
)

โปรดทราบว่าออบเจ็กต์ที่ส่งคืนให้กับบล็อก cb เป็นอินสแตนซ์ใหม่ของ CampaignBudget ซึ่งคุณสามารถเปลี่ยนแปลง และการดำเนินการสร้างที่เหมาะสมสำหรับ ส่งคืน CampaignBudgetService แล้ว

และเช่นเดียวกัน เรามีวิธีอำนวยความสะดวกในการอัปเดตดังต่อไปนี้

# if you only have a resource name
update_operation = client.operation.update_resource.campaign(campaign_resource_name) do |camp|
  camp.status = :PAUSED
end

campaign_service.mutate_campaigns(customer_id, [update_operation])

# if you have a full resource proto
update_operation = client.operation.update_resource.campaign(campaign) do
  campaign.name = "A different interplanetary Cruise #{(Time.new.to_f * 1000).to_i}"
end

campaign_service.mutate_campaigns(customer_id, [update_operation])

การเรียกเหล่านี้ส่งคืนการดำเนินการอัปเดตที่มีรูปแบบถูกต้อง พร้อมด้วยฟิลด์ เพื่อช่วยอัปเดตทรัพยากรใน Google Ads API

ต่อไปนี้คือตัวอย่างของการนำทรัพยากรออกโดยใช้เส้นทางทรัพยากร

remove_operation = client.operation.remove_resource.campaign(campaign_resource_name)
campaign_service.mutate_campaigns(customer_id, [remove_operation])

หากต้องการดำเนินการด้วยตนเอง คุณสามารถรับการดำเนินการดิบได้ แล้วเติมข้อมูลในช่องด้วยตนเอง

operation = client.operation.campaign

แหล่งข้อมูล

ห้องสมุดให้ client.resource.<resource_type> ซึ่งเป็นวิธีที่สะดวกในการ เริ่มต้นออบเจ็กต์ทรัพยากร:

campaign.network_settings = client.resource.network_settings do |ns|
  ns.target_google_search = true
  ns.target_search_network = true
  ns.target_content_network = false
  ns.target_partner_search_network = false
end

มีการส่งอินสแตนซ์ใหม่ของประเภททรัพยากรที่ขอไปยังการบล็อกที่ส่งผ่านสำหรับ การตั้งค่า

บริการ

ห้องสมุดให้ client.service.<service_name> ซึ่งเป็นวิธีที่สะดวกในการ รับออบเจ็กต์บริการ:

campaign_service = client.service.campaign

Enum

เราขอแนะนำให้ใช้ไวยากรณ์สัญลักษณ์สำหรับการตั้งค่าช่อง enum แบบคงที่ (เช่น campaign.status = :PAUSED) แต่หากต้องการแจกแจงรายละเอียดทั้งหมด ค่าที่ถูกต้องสำหรับ enum เรามีเมธอดดังนี้

client.enum.ad_type.each { |x| p x }
    :SHOPPING_PRODUCT_AD
    :GMAIL_AD
    :UNKNOWN
    :UNSPECIFIED
    :CALL_ONLY_AD
    :VIDEO_AD
    :IMAGE_AD
    :EXPANDED_DYNAMIC_SEARCH_AD
    :RESPONSIVE_DISPLAY_AD
    :TEXT_AD
    :LEGACY_RESPONSIVE_DISPLAY_AD
    :LEGACY_APP_INSTALL_AD
    :APP_AD
    :SHOPPING_SMART_AD
    :EXPANDED_TEXT_AD
    :HOTEL_AD
    :RESPONSIVE_SEARCH_AD

ตั้งค่าเวอร์ชัน Google Ads API อย่างชัดแจ้ง

คุณยังกำหนดเวอร์ชันอย่างชัดแจ้งได้อีกด้วย โดยทำดังนี้

client.resource.v22.[entity]
client.operation.v22.[operation]
client.service.v22.[service]
client.enum.v22.[enum]