ข้อควรระวัง: คุณกําลังดูเอกสารประกอบสําหรับอินเทอร์เฟซ REST ของ API ไลบรารีของไคลเอ็นต์อย่างเป็นทางการส่วนใหญ่ของเราใช้ gRPC โปรดดูรายละเอียดใน
บทนํา REST
การแมป JSON
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เมื่อใช้ REST Interface ของ Google Ads API คุณจะทำงานกับตัวแทน JSON
ของทรัพยากรและประเภทเดียวกันที่กำหนดไว้ในไฟล์ตัวอธิบาย .proto ของ Google Ads API รูปแบบการเข้ารหัส JSON เป็นไปตามรูปแบบการเข้ารหัสที่ชัดเจนซึ่งอธิบายไว้ในส่วนการแมป JSON ของคำแนะนำเกี่ยวกับภาษาของ Protocol Buffer
โดยทั่วไป ข้อความระดับบนสุดทั้งหมดที่ส่งไปยังและจากบริการจะเป็นออบเจ็กต์ JSON เดียว
คำขอเปลี่ยนแปลงส่วนใหญ่มีอาร์เรย์ operations
ซึ่งมี
การดำเนินการ create
, update
หรือ delete
จำนวนมาก ในทำนองเดียวกัน คำตอบของ search
คือออบเจ็กต์ JSON ที่มีอาร์เรย์ results
พร้อมชุดผลลัพธ์ของการค้นหา
ตัวระบุจะเปลี่ยนจาก snake_case (ในบัฟเฟอร์โปรโตคอล) เป็น
lowerCamelCase ใน JSON ข้อควรระวังที่สำคัญอย่างหนึ่งของกฎนี้คือเมื่อใช้
search
หรือ searchStream
เพื่อส่งคำค้นหาภาษาของคำค้นหาของ Google Ads
ภาษาของคําค้นหาเองจะใช้รูปแบบ Snake Case ไม่ว่าคุณจะใช้อินเทอร์เฟซใดก็ตาม
อย่างไรก็ตาม ผลลัพธ์ของการค้นหาใน REST จะแสดงเป็น
ออบเจ็กต์ JSON ปกติและมีตัวระบุในรูปแบบ lowerCamelCase
เช่น คำค้นหาเพื่อดึงรายการคีย์เวิร์ดที่ใช้งานอยู่ในบัญชีจะใช้
รูปแบบตัวพิมพ์เล็กคั่นด้วยขีดล่างภายในคำค้นหาเอง (ad_group_criterion
ไม่ใช่ adGroupCriterion
)
POST /v21/customers/CUSTOMER_ID/googleAds:searchStream HTTP/1.1
Host: googleads.googleapis.com
Content-Type: application/json
Authorization: Bearer ACCESS_TOKEN
developer-token: DEVELOPER_TOKEN
{
"query": "SELECT ad_group_criterion.keyword.text
FROM ad_group_criterion
WHERE ad_group_criterion.type = 'KEYWORD'
AND ad_group_criterion.status = 'ENABLED'"
}
อย่างไรก็ตาม การตอบกลับคือการแสดงออบเจ็กต์ในรูปแบบ JSON (อยู่ในอาร์เรย์ JSON เนื่องจากคำขอนี้ใช้ searchStream
) และใช้ตัวระบุ camelCase
adGroupCriterion
แทน
[
{
"results": [
{
"adGroupCriterion": {
"resourceName": "customers/1842689525/adGroupCriteria/55771861891~10003060",
"keyword": {
"text": "pay per click"
}
}
},
...
]
}
]
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-27 UTC
[null,null,["อัปเดตล่าสุด 2025-08-27 UTC"],[[["\u003cp\u003eThe Google Ads API's REST interface uses JSON to represent resources and types, following the protocol buffers' JSON encoding scheme.\u003c/p\u003e\n"],["\u003cp\u003eTop-level messages in the REST interface are JSON objects, with mutate requests typically containing an \u003ccode\u003eoperations\u003c/code\u003e array and search responses containing a \u003ccode\u003eresults\u003c/code\u003e array.\u003c/p\u003e\n"],["\u003cp\u003eIdentifiers are generally transformed from \u003cem\u003esnake_case\u003c/em\u003e to \u003cem\u003elowerCamelCase\u003c/em\u003e in JSON, with the exception of Google Ads Query Language queries, which use snake case.\u003c/p\u003e\n"],["\u003cp\u003eWhile Google Ads Query Language queries use snake case, the results returned through the REST interface utilize \u003cem\u003elowerCamelCase\u003c/em\u003e for identifiers within the JSON response objects.\u003c/p\u003e\n"]]],[],null,["# JSON Mappings\n\nWhen using the Google Ads API's REST interface, you're working with JSON\nrepresentations of the same resources and types defined in the Google Ads API's\n[.proto descriptor](https://github.com/googleapis/googleapis/tree/master/google/ads/googleads) files. The JSON encoding scheme follows the\ncanonical encoding scheme described in the\n[JSON Mapping](/protocol-buffers/docs/proto3#json) section of the protocol\nbuffers *Language Guide*.\n\nIn general, all top-level messages to and from\n[services](https://github.com/googleapis/googleapis/tree/master/google/ads/googleads/v21/services) are single JSON objects.\nMost mutate requests contain an `operations` array that itself contains many\n`create`, `update`, or `delete` operations. Similarly, `search` responses are\nJSON objects containing a `results` array with your query's result set.\n\nIdentifiers are transformed from *snake_case* (in protocol buffers) to\n*lowerCamelCase* in JSON. One notable caveat to this rule is when using\n`search` or `searchStream` to send [Google Ads Query Language](/google-ads/api/docs/query/overview)\nqueries. The query language itself uses snake case, regardless of which\ninterface you're using. However, the results of a query in REST are returned as\nnormal JSON objects and have their identifiers in lowerCamelCase.\n\nFor example, a query to fetch a list of active keywords in an account uses\nsnake case inside the query itself (`ad_group_criterion`, not `adGroupCriterion`): \n\n```http\nPOST /v21/customers/\u003cvar translate=\"no\"\u003eCUSTOMER_ID\u003c/var\u003e/googleAds:searchStream HTTP/1.1\nHost: googleads.googleapis.com\nContent-Type: application/json\nAuthorization: Bearer \u003cvar translate=\"no\"\u003eACCESS_TOKEN\u003c/var\u003e\ndeveloper-token: DEVELOPER_TOKEN\n\n{\n \"query\": \"SELECT ad_group_criterion.keyword.text\n FROM ad_group_criterion\n WHERE ad_group_criterion.type = 'KEYWORD'\n AND ad_group_criterion.status = 'ENABLED'\"\n}\n```\n\nHowever, the response is a JSON representation of the objects (wrapped in a JSON\narray since this request uses `searchStream`) and uses the camelCase identifier\n`adGroupCriterion` instead: \n\n```javascript\n[\n {\n \"results\": [\n {\n \"adGroupCriterion\": {\n \"resourceName\": \"customers/1842689525/adGroupCriteria/55771861891~10003060\",\n \"keyword\": {\n \"text\": \"pay per click\"\n }\n }\n },\n ...\n ]\n }\n]\n```"]]