รายงานสตรีมมิงโดยใช้ GoogleAdsService
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
หากต้องการดึงข้อมูลเอนทิตี Google Ads API และข้อมูลการรายงาน ให้ใช้วิธีใดวิธีหนึ่งต่อไปนี้
ความแตกต่างในระดับสูงของทั้ง 2 วิธีมีดังนี้
|
GoogleAdsService.SearchStream |
GoogleAdsService.Search |
เหมาะสำหรับโค้ดที่ใช้งานจริง |
มี |
มี |
บริการ |
GoogleAdsService |
GoogleAdsService |
สถานการณ์ |
การดึงข้อมูลออบเจ็กต์และรายงาน |
การดึงข้อมูลออบเจ็กต์และรายงาน |
การตอบกลับ |
สตรีมของออบเจ็กต์ GoogleAdsRow |
หน้าของออบเจ็กต์ GoogleAdsRow |
ฟิลด์ของคำตอบ |
เฉพาะที่ระบุในการค้นหา |
เฉพาะที่ระบุในการค้นหา |
ขีดจำกัดการใช้งานต่อวัน |
โควต้าการใช้งานรายวันตามระดับการเข้าถึง |
โควต้าการใช้งานรายวันตามระดับการเข้าถึง |
SearchStream
เทียบกับ Search
แม้ว่า Search
จะส่งคำขอแบบแบ่งหน้าหลายรายการเพื่อดาวน์โหลดรายงานทั้งหมดได้ แต่ SearchStream
จะส่งคำขอเดียวและเริ่มการเชื่อมต่อแบบถาวรกับ Google Ads API โดยไม่คำนึงถึงขนาดรายงาน
สำหรับ SearchStream
ระบบจะเริ่มดาวน์โหลดแพ็กเก็ตข้อมูลทันทีพร้อมกับแคชผลลัพธ์ทั้งหมด
ในบัฟเฟอร์ข้อมูล โค้ดจะเริ่มอ่านข้อมูลที่บัฟเฟอร์ได้
โดยไม่ต้องรอให้สตรีมทั้งหมดเสร็จสิ้น
การลดเวลาในการรับส่งข้อมูลผ่านเครือข่ายที่จำเป็นในการขอแต่ละหน้าของคำตอบ Search
จะช่วยให้ SearchStream
มีประสิทธิภาพดีกว่าการแบ่งหน้า โดยเฉพาะอย่างยิ่งสำหรับรายงานขนาดใหญ่
ตัวอย่าง
ตัวอย่างนี้จะดูรายงานที่มี 100,000
แถว ตารางต่อไปนี้จะแสดงรายละเอียดความแตกต่างด้านการบัญชีระหว่าง 2 วิธี
|
SearchStream |
ค้นหา |
ขนาดหน้า |
ไม่เกี่ยวข้อง |
10,000 แถวต่อหน้า |
จำนวนคำขอ API |
คำขอ 1 รายการ |
คำขอ 10 รายการ |
จำนวนการตอบกลับจาก API |
1 สตรีมแบบต่อเนื่อง |
คำตอบ 10 รายการ |
สำหรับกรณีการใช้งานส่วนใหญ่ เราขอแนะนำให้ใช้ SearchStream
แทน Search
ด้วยเหตุผลต่อไปนี้
สำหรับรายงานแบบหน้าเดียว (ไม่เกิน 10,000 แถว): ประสิทธิภาพของทั้ง 2 วิธีไม่แตกต่างกันอย่างมีนัยสำคัญ
สำหรับรายงานแบบหลายหน้า SearchStream
มักจะเร็วกว่าเนื่องจากไม่ต้องมีการรับส่งหลายรอบ และการอ่านหรือเขียนจากแคชในดิสก์ก็ไม่ใช่ปัจจัยสำคัญ
ขีดจำกัดอัตรา
ขีดจำกัดรายวันสำหรับทั้ง 2 วิธีจะเป็นไปตามขีดจำกัดมาตรฐานและระดับการเข้าถึงของโทเค็นนักพัฒนาแอป ระบบจะนับการค้นหาหรือรายงานเดียวเป็นการดำเนินการ 1 รายการ ไม่ว่าผลลัพธ์จะมีการแบ่งหน้าหรือสตรีมก็ตาม
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-27 UTC
[null,null,["อัปเดตล่าสุด 2025-08-27 UTC"],[[["\u003cp\u003eThe Google Ads API offers two primary methods for retrieving data: \u003ccode\u003eSearchStream\u003c/code\u003e and \u003ccode\u003eSearch\u003c/code\u003e, both suitable for production environments and fetching objects and reports.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eSearchStream\u003c/code\u003e delivers results as a continuous stream, ideal for large reports, while \u003ccode\u003eSearch\u003c/code\u003e provides paginated responses.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eSearchStream\u003c/code\u003e often offers performance advantages by reducing network round trips, especially for reports exceeding 10,000 rows.\u003c/p\u003e\n"],["\u003cp\u003eBoth methods are subject to the same daily limits and access levels, with a single query or report counting as one operation regardless of the method.\u003c/p\u003e\n"],["\u003cp\u003eGoogle recommends using \u003ccode\u003eSearchStream\u003c/code\u003e for most use cases due to its performance benefits for larger reports.\u003c/p\u003e\n"]]],[],null,["# Report streaming using GoogleAdsService\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nTo retrieve Google Ads API entities and reporting data, use one of these methods:\n\n- [`GoogleAdsService.SearchStream`](/google-ads/api/reference/rpc/v21/GoogleAdsService/SearchStream)\n- [`GoogleAdsService.Search`](/google-ads/api/reference/rpc/v21/GoogleAdsService/Search)\n\nHere are the high-level distinctions for the two methods:\n\n| | GoogleAdsService.SearchStream | GoogleAdsService.Search |\n| Suitable for production code | **Yes** | **Yes** |\n| Service | [`GoogleAdsService`](/google-ads/api/reference/rpc/v21/GoogleAdsService) | [`GoogleAdsService`](/google-ads/api/reference/rpc/v21/GoogleAdsService) |\n| Scenario | Fetching objects and reports | Fetching objects and reports |\n| Response | **Stream** of [`GoogleAdsRow`](/google-ads/api/reference/rpc/v21/GoogleAdsRow) objects | Pages of [`GoogleAdsRow`](/google-ads/api/reference/rpc/v21/GoogleAdsRow) objects |\n| Response's fields | Only those specified in the query | Only those specified in the query |\n| Daily limits | Daily limits based on [access levels](/google-ads/api/docs/access-levels) | Daily limits based on [access levels](/google-ads/api/docs/access-levels) |\n|------------------------------|----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------|\n\n`SearchStream` versus `Search`\n------------------------------\n\nWhile [`Search`](/google-ads/api/reference/rpc/v21/GoogleAdsService/Search) can send multiple\npaginated requests to download the entire report, [`SearchStream`](/google-ads/api/reference/rpc/v21/GoogleAdsService/SearchStream) sends a single request and\ninitiates a persistent connection with the Google Ads API regardless of report size.\n\nFor `SearchStream`, data packets start to download immediately with the entire\nresult cached in a data buffer. Your code can start reading the buffered data\nwithout having to wait for the entire stream to finish.\n\nBy eliminating the round-trip network time required to request each individual\npage of a `Search` response, depending on your app, `SearchStream` can offer\nimproved performance over paging, especially for bigger reports.\n\n### Example\n\nThis example looks at a report that consists of `100,000` rows. The following\ntable breaks down the accounting differences between the two methods.\n\n| | SearchStream | Search |\n| Page size | Not Applicable | 10,000 rows per page |\n| Number of API requests | 1 request | 10 requests |\n| Number of API responses | 1 continuous stream | 10 responses |\n|-------------------------|---------------------|----------------------|\n\n### Performance factors\n\nFor most use cases, we recommend `SearchStream` over `Search` for the following\nreasons:\n\n- For single page reports (under 10,000 rows): No significant performance\n differences between the two methods.\n\n- For multiple page reports: `SearchStream` is typically faster since multiple\n round trips are avoided, and reading or writing from disk cache is less of a\n factor.\n\n### Rate limits\n\nDaily limits for both methods adhere to the standard limits and [access\nlevels](/google-ads/api/docs/access-levels) of your developer token. A single query or report\nis counted as one operation regardless of the result being paged or streamed."]]