تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
في Google Ads API، يتم تعريف بعض حقول الرسائل على أنّها كائنات رسائل فارغة، مثل campaign.manual_cpm، أو قد تحتوي فقط على حقول اختيارية لا يلزم ضبطها، مثل campaign.manual_cpc.
من المهم ضبط هذه الحقول لإخبار واجهة برمجة التطبيقات باستراتيجية عروض الأسعار التي يجب استخدامها للحملة المحدّدة، ولكن لا يكون ذلك واضحًا عندما تكون الرسائل فارغة.
عند تعديل الحقل campaign.name، وهو سلسلة، نضبط الحقل
من خلال تعديله مباشرةً كما لو كان سمة عادية لكائن Python:
campaign.name="Test campaign value"
campaign.manual_cpc هو حقل مدمج، ما يعني أنّه يحتوي على رسالة protobuf أخرى وليس نوعًا أساسيًا، مثل سلسلة. يمكنك أيضًا تعديل حقوله مباشرةً باتّباع الخطوات التالية:
campaign.manual_cpc.enhanced_cpc_enabled=True
سيُعلم ذلك واجهة برمجة التطبيقات بأنّ هذه الحملة تستخدم استراتيجية عروض أسعار manual_cpc
مع تفعيل ميزة "تكلفة النقرة المحسّنة".
ولكن ماذا لو أردت استخدام manual_cpm، وهو فارغ؟ أو manual_cpc
بدون تفعيل تكلفة النقرة المحسّنة؟ لإجراء ذلك، عليك نسخ نسخة منفصلة وفارغة من الفئة إلى الحملة، على سبيل المثال:
تم ضبط الحقل manual_cpm، ولكن لا تحتوي أي من حقوله على قيم. عند إرسال طلب إلى واجهة برمجة التطبيقات التي تستخدم هذا النمط، يمكنك التأكّد من ضبط عنصر الرسالة الفارغة بشكل صحيح من خلال تفعيل التسجيل وفحص حمولة الطلب.
أخيرًا، عليك إضافة هذا الحقل يدويًا إلى update_mask الخاص بكائن الطلب. لا تتضمّن أداة المساعدة الخاصة بقناع الحقل آلية لتحديد الفرق بين حقل تم ضبطه بشكل صريح على عنصر فارغ وحقل لم يتم ضبطه.
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")
تاريخ التعديل الأخير: 2025-08-27 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-08-27 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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\")"]]