Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Google Ads API'de bazı ileti alanları boş ileti nesneleri olarak tanımlanır (ör. campaign.manual_cpm) veya yalnızca ayarlanması gerekmeyen isteğe bağlı alanlara sahip olabilir (ör. campaign.manual_cpc).
Bu alanları ayarlamak, API'ye belirli bir kampanya için hangi teklif stratejisinin kullanılacağını bildirmek açısından önemlidir ancak mesajlar boş olduğunda bu işlem sezgisel değildir.
Dize olan campaign.name alanını güncellerken alanı, normal bir Python nesne özelliğiymiş gibi doğrudan güncelleyerek ayarlıyoruz:
campaign.name="Test campaign value"
campaign.manual_cpc, iç içe yerleştirilmiş bir alandır. Yani dize gibi temel bir tür değil, başka bir protobuf mesajı içerir. Alanlarını doğrudan da güncelleyebilirsiniz:
campaign.manual_cpc.enhanced_cpc_enabled=True
Bu, API'ye bu kampanyanın manual_cpc
Geliştirilmiş TBM'nin etkin olduğu bir teklif stratejisine sahip olduğunu bildirir.
Ancak boş olan manual_cpm öğesini kullanmak isterseniz ne olur? Yoksa manual_cpc
geliştirilmiş TBM'yi etkinleştirmeden mi? Bunu yapmak için sınıfın ayrı bir boş örneğini kampanyaya kopyalamanız gerekir. Örneğin:
campaign nesnesi için manual_cpm öğesinin nasıl belirtildiğine dikkat edin:
name{value:"Test campaign value"}
manual_cpm{}
manual_cpm alanı ayarlanmış ancak alanlarından hiçbirinde değer yok. Bu kalıbı kullanan API'ye istek gönderirken günlüğü etkinleştirip istek yükünü inceleyerek boş mesaj nesnesini doğru şekilde ayarladığınızı doğrulayabilirsiniz.
Son olarak, bu alanı istek nesnesinin update_mask bölümüne manuel olarak eklemeniz gerekir. Alan maskesi yardımcısında, açıkça boş bir nesneye ayarlanmış bir alan ile ayarlanmamış bir alan arasındaki farkı belirleyecek bir mekanizma yoktur.
fromgoogle.api_core.protobuf_helpersimportfield_maskcampaign_operation.create=campaigncampaign_operation.update_mask=field_mask(None,campaign)# Here we manually add the "manual_cpm" fieldcampaign_operation.update_mask.append("manual_cpm")
[[["Anlaması kolay","easyToUnderstand","thumb-up"],["Sorunumu çözdü","solvedMyProblem","thumb-up"],["Diğer","otherUp","thumb-up"]],[["İhtiyacım olan bilgiler yok","missingTheInformationINeed","thumb-down"],["Çok karmaşık / çok fazla adım var","tooComplicatedTooManySteps","thumb-down"],["Güncel değil","outOfDate","thumb-down"],["Çeviri sorunu","translationIssue","thumb-down"],["Örnek veya kod sorunu","samplesCodeIssue","thumb-down"],["Diğer","otherDown","thumb-down"]],["Son güncelleme tarihi: 2025-09-05 UTC."],[[["\u003cp\u003eSome Google Ads API message fields are defined as empty or only have optional fields, requiring specific handling to indicate the intended bidding strategy.\u003c/p\u003e\n"],["\u003cp\u003eTo set a bidding strategy using an empty message field (like \u003ccode\u003emanual_cpm\u003c/code\u003e), you need to copy a separate empty instance of the corresponding class onto the campaign object.\u003c/p\u003e\n"],["\u003cp\u003eNested fields within messages (like \u003ccode\u003ecampaign.manual_cpc.enhanced_cpc_enabled\u003c/code\u003e) can be updated directly like normal Python object attributes.\u003c/p\u003e\n"],["\u003cp\u003eWhen using empty message objects, ensure the field is added to the request's \u003ccode\u003eupdate_mask\u003c/code\u003e manually, as the field mask helper cannot automatically detect this.\u003c/p\u003e\n"]]],[],null,["# Setting Empty Message Objects as Fields\n\nIn the Google Ads API some message fields are defined as empty message objects,\nsuch as [`campaign.manual_cpm`](/google-ads/api/fields/v21/campaign#campaign.manual_cpm),\nor they may only have optional fields that don't need to be set, for example\n[`campaign.manual_cpc`](/google-ads/api/fields/v21/campaign#campaign.manual_cpc.enhanced_cpc_enabled).\nSetting these fields is important to tell the API which bidding strategy to use\nfor the given Campaign, but it's not intuitive when the messages are empty.\n\nWhen updating the `campaign.name` field, which is a string, we set the field\nby updating it directly as if it were a normal Python object attribute: \n\n campaign.name = \"Test campaign value\"\n\n`campaign.manual_cpc` is a nested field, meaning it contains\nanother protobuf message and not a primitive type, like a string. You\ncan update its fields directly as well: \n\n campaign.manual_cpc.enhanced_cpc_enabled = True\n\nThis will tell the API that this Campaign has a bidding strategy of `manual_cpc`\nwith enhanced CPC enabled.\n\nBut what if you want to use `manual_cpm`, which is empty? Or `manual_cpc`\nwithout enabling enhanced cpc? To do this you will need to copy a separate\nempty instance of the class onto the campaign, for example: \n\n client = GoogleAdsClient.load_from_storage()\n\n empty_cpm = client.get_type('ManualCpm')\n client.copy_from(campaign.manual_cpm, empty_cpm)\n\nNote how `manual_cpm` is specified for the `campaign` object: \n\n name {\n value: \"Test campaign value\"\n }\n manual_cpm {\n }\n\nThe `manual_cpm` field is set, but none of its fields have values. When sending\nrequest to the API that use this pattern, you can verify that you're setting the\nempty message object correctly by enabling [logging](/google-ads/api/docs/client-libs/python/logging) and inspecting the\nrequest payload.\n\nLastly, you'll need to manually add this field to the request object's\n`update_mask`. The field mask helper has no mechanism to determine the\ndifference between a field that's been explicitly set to an empty object, and a\nfield that hasn't been set. \n\n from google.api_core.protobuf_helpers import field_mask\n\n campaign_operation.create = campaign\n campaign_operation.update_mask = field_mask(None, campaign)\n # Here we manually add the \"manual_cpm\" field\n campaign_operation.update_mask.append(\"manual_cpm\")"]]