ชื่อทรัพยากร
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ตัวระบุที่ไม่ซ้ำกันสำหรับเอนทิตีใน Google Ads API เรียกว่าชื่อทรัพยากร
และแสดงเป็นสตริงที่มีรูปแบบที่คาดการณ์ได้ หากทราบ
คอมโพเนนต์ที่เป็นส่วนประกอบของชื่อทรัพยากร คุณจะสร้างชื่อทรัพยากร
ได้โดยใช้วิธีการช่วยที่มีอยู่ในออบเจ็กต์บริการหลายรายการ
วิธีการเส้นทางบริการ
บริการทั้งหมดที่ออกแบบมาเพื่อจัดการการอ่านหรือการเปลี่ยนแปลงออบเจ็กต์ประเภทใดประเภทหนึ่งใน API มีเมธอดตัวช่วยในการสร้าง resource_names เช่น คุณสร้างชื่อทรัพยากรสำหรับออบเจ็กต์ Campaign
ได้ดังนี้
from google.ads.googleads.client import GoogleAdsClient
client = GoogleAdsClient.load_from_storage()
customer_id = "7892134783"
campaign_id = "1234567890"
campaign_service = client.get_service("CampaignService")
resource_name = campaign_service.campaign_path(customer_id, campaign_id)
นอกจากนี้ แต่ละบริการยังมีเมธอด parse_*_path
ที่เกี่ยวข้องซึ่งจะแยกวิเคราะห์
resource_name ออกเป็นแต่ละส่วน เช่น
from google.ads.googleads.client import GoogleAdsClient
client = GoogleAdsClient.load_from_storage()
resource_name = "customers/7892134783/campaigns/1234567890"
campaign_service = client.get_service('CampaignService')
segments = campaign_service.parse_campaign_path(resource_name)
customer_id = segments["customer_id"]
campaign_id = segments["campaign_id"]
ชื่อทรัพยากรแบบผสม
ตัวช่วยเส้นทางในบริการจะสร้างกลุ่มแบบผสมของชื่อทรัพยากร ระบบยอมรับส่วนต่างๆ ของรหัสแบบรวมเป็นพารามิเตอร์แต่ละรายการใน
เมธอด ดังนี้
from google.ads.google_ads.client import GoogleAdsClient
customer_id = "0987654321"
ad_group_id = "1234567890"
criterion_id = "74932"
client = GoogleAdsClient.load_from_storage()
ad_group_criterion_service = client.get_service("AdGroupCriterionService")
# An AdGroupCriterion resource name that uses the above IDs looks like this:
# "customers/0987654321/adGroupCriteria/1234567890~74932"
resource_name = ad_group_criterion_service.ad_group_criterion_path(
customer_id, ad_group_id, criterion_id
)
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-27 UTC
[null,null,["อัปเดตล่าสุด 2025-08-27 UTC"],[[["\u003cp\u003eIn the Google Ads API, entities are uniquely identified by a predictable string format called a resource name.\u003c/p\u003e\n"],["\u003cp\u003eHelper methods on Service objects can be used to generate these resource names if you know the required components.\u003c/p\u003e\n"],["\u003cp\u003eServices offer path methods like \u003ccode\u003ecampaign_path\u003c/code\u003e to build resource names and \u003ccode\u003eparse_campaign_path\u003c/code\u003e to break them down into individual segments.\u003c/p\u003e\n"],["\u003cp\u003eComposite resource names, such as those for AdGroupCriterion, are constructed by path helpers using multiple ID segments as parameters.\u003c/p\u003e\n"]]],[],null,["# Resource Names\n\nThe unique identifier for an entity in the Google Ads API is called a resource\nname, and is represented as a string with a predictable format. If you know\nthe constituent components of a resource name, you can generate resource names\nusing helper methods present on many Service objects.\n\nService path methods\n--------------------\n\nAll Services that are designed to handle reading or mutating specific types of\nobjects in the API have helper methods to construct resource_names. For example,\nyou can create a resource name for a `Campaign` object: \n\n from google.ads.googleads.client import GoogleAdsClient\n\n client = GoogleAdsClient.load_from_storage()\n customer_id = \"7892134783\"\n campaign_id = \"1234567890\"\n campaign_service = client.get_service(\"CampaignService\")\n resource_name = campaign_service.campaign_path(customer_id, campaign_id)\n\nEach service also has an accompanying `parse_*_path` method that deconstructs a\nresource_name into its individual segments, for example: \n\n from google.ads.googleads.client import GoogleAdsClient\n\n client = GoogleAdsClient.load_from_storage()\n resource_name = \"customers/7892134783/campaigns/1234567890\"\n campaign_service = client.get_service('CampaignService')\n segments = campaign_service.parse_campaign_path(resource_name)\n customer_id = segments[\"customer_id\"]\n campaign_id = segments[\"campaign_id\"]\n\nComposite resource names\n------------------------\n\nPath helpers on services construct composite segments of a resource name. The\ndifferent segments of the composite ID are accepted as individual parameters in\nthe method: \n\n from google.ads.google_ads.client import GoogleAdsClient\n\n customer_id = \"0987654321\"\n ad_group_id = \"1234567890\"\n criterion_id = \"74932\"\n\n client = GoogleAdsClient.load_from_storage()\n ad_group_criterion_service = client.get_service(\"AdGroupCriterionService\")\n\n # An AdGroupCriterion resource name that uses the above IDs looks like this:\n # \"customers/0987654321/adGroupCriteria/1234567890~74932\"\n resource_name = ad_group_criterion_service.ad_group_criterion_path(\n customer_id, ad_group_id, criterion_id\n )"]]