การทดสอบ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
การทดสอบเป็นขั้นตอนสำคัญในการสร้างการผสานรวม Google Ads API ที่ประสบความสำเร็จ
ไม่ว่าคุณจะเพิ่งเริ่มต้น บํารุงรักษาแอป หรือเพิ่ม
ฟีเจอร์ใหม่ๆ ลงในการผสานรวมที่มีอยู่ คู่มือนี้จะนำเสนอแนวทางปฏิบัติแนะนำบางส่วนสำหรับการทดสอบการผสานรวม Google Ads API
บัญชีทดสอบและบัญชีจริง
บัญชีทดสอบพร้อมให้ใช้งานเพื่อ
วัตถุประสงค์ในการพัฒนา บัญชีทดสอบช่วยให้คุณตรวจสอบได้ว่าโค้ดและการกำหนดค่าแอปพลิเคชัน
ทำงานได้ตามที่ต้องการ
อย่างไรก็ตาม คุณทดสอบฟีเจอร์บางอย่างในบัญชีทดสอบไม่ได้
เมื่อข้อจำกัดของบัญชีทดสอบทำให้คุณทดสอบฟีเจอร์บางอย่างในการผสานรวมไม่ได้ คุณสามารถใช้บัญชีจริงในการพัฒนาแทนได้
บัญชีที่ใช้งานจริงสำหรับการพัฒนาจะแตกต่างจากบัญชีทดสอบในลักษณะต่อไปนี้
- แสดงโฆษณาที่ผู้ใช้มองเห็นได้
- ต้องระบุ URL ที่ถูกต้อง
- ต้องเป็นไปตามนโยบายการโฆษณา
เนื่องจากบัญชีจริงแสดงโฆษณา จึงสร้างเมตริกที่ช่วยให้คุณทดสอบรายงานประสิทธิภาพ รวมถึงปลดล็อกฟีเจอร์อื่นๆ ทั้งหมดของ Google Ads API ได้ อย่างไรก็ตาม การใช้ฟีเจอร์เหล่านี้ในการพัฒนาต้องใช้ความระมัดระวังเป็นพิเศษ เรา
ขอแนะนำให้ใช้มาตรการต่อไปนี้
- ให้สิทธิ์เข้าถึงแก่ผู้ใช้ที่จำเป็นต้องใช้เพื่อวัตถุประสงค์ในการพัฒนาเท่านั้น
- กำหนดงบประมาณบัญชีรายวันแบบคงที่ในระดับต่ำ
- ใช้บัญชีเวอร์ชันที่ใช้งานจริงสำหรับการพัฒนาเฉพาะในกรณีที่ไม่สามารถใช้บัญชีทดสอบได้
ดังนั้น หากต้องการทดสอบการผสานรวมอย่างเต็มรูปแบบ คุณอาจต้องใช้ทั้งข้อมูลเข้าสู่ระบบที่ใช้ทดสอบและข้อมูลเข้าสู่ระบบที่ใช้ในการผลิต
ข้อมูลเข้าสู่ระบบที่ใช้ทดสอบ
เราขอแนะนำให้เก็บชุดข้อมูลเข้าสู่ระบบทดสอบแยกต่างหากจากข้อมูลเข้าสู่ระบบของแอปพลิเคชันที่ใช้งานจริง เพื่อลดความเสี่ยงในการแก้ไขบัญชีที่ใช้งานจริงโดยไม่ตั้งใจเมื่อพยายามแก้ไขบัญชีสำหรับการพัฒนา
วิธีสร้างชุดข้อมูลเข้าสู่ระบบทดสอบ
- สร้างบัญชีอีเมล (เช่น api.test@example.com) หรือบัญชีบริการ
ที่จะใช้เพื่อการทดสอบเท่านั้น
- เพิ่มผู้ใช้หรือบัญชีบริการนี้เป็นผู้ใช้ที่ถูกต้องในบัญชี Google Ads ที่คุณ
ใช้ทดสอบ ตรวจสอบว่าคุณได้ให้ระดับการเข้าถึงที่เหมาะสม
แก่ผู้ใช้หรือบัญชีบริการนี้ อย่าให้สิทธิ์เข้าถึงบัญชีเวอร์ชันที่ใช้งานจริงแก่ผู้ใช้หรือบัญชีบริการนี้
- หากคุณใช้ขั้นตอนการตรวจสอบสิทธิ์ผู้ใช้ OAuth 2.0 แทนขั้นตอนบัญชีบริการ ให้สร้างโทเค็นการรีเฟรชสำหรับบัญชีผู้ใช้ทดสอบ
- ใช้ข้อมูลเข้าสู่ระบบใหม่เหล่านี้เมื่อทดสอบแอปพลิเคชัน คุณสามารถนำโทเค็นนักพัฒนาแอป
รหัสไคลเอ็นต์ และข้อมูลลับของไคลเอ็นต์มาใช้ซ้ำเพื่อวัตถุประสงค์ในการทดสอบได้ เนื่องจาก
ไม่มีผลต่อการพิจารณาว่าบัญชี Google Ads ใดที่เข้าถึงได้
ขอการตรวจสอบ
หากเพียงต้องการทดสอบว่าคำขอถูกต้องหรือไม่ เช่น เพื่อ
ยืนยันว่าคำขอมีโครงสร้างถูกต้องและไม่ละเมิด
นโยบาย คุณสามารถใช้ฟิลด์
validate_only
ซึ่งใช้ได้กับคำขอ GoogleAdsService.SearchStream
และ
GoogleAdsService.Search
รวมถึงคำขอ mutate ส่วนใหญ่
โปรดดูเอกสารอ้างอิงเพื่อตรวจสอบว่าฟิลด์นี้ใช้ได้กับเมธอดที่ต้องการหรือไม่
REST API
สำหรับการทดสอบเฉพาะกิจ เช่น เพื่อตรวจสอบว่าคำขอให้ผลลัพธ์ตามที่คาดไว้ การใช้ REST API มักเป็นตัวเลือกที่ง่ายที่สุด โปรดดูตัวอย่าง REST เพื่อดูวิธีใช้ curl ในการส่ง
คำขอไปยัง REST API นอกจากนี้ ให้ลองทดสอบในREST Explorer ด้วย
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-26 UTC
[null,null,["อัปเดตล่าสุด 2025-08-26 UTC"],[[["\u003cp\u003eTesting is crucial for successful Google Ads API integration, whether you're starting fresh, maintaining an app, or adding features.\u003c/p\u003e\n"],["\u003cp\u003eUtilize test accounts for development when possible, but be aware of their limitations and consider using production accounts cautiously for features not supported by test accounts.\u003c/p\u003e\n"],["\u003cp\u003eMaintain separate test credentials, especially refresh tokens, to avoid accidental modifications to production accounts.\u003c/p\u003e\n"],["\u003cp\u003eValidate your requests using the \u003ccode\u003evalidate_only\u003c/code\u003e field to ensure they are structured correctly and comply with policies.\u003c/p\u003e\n"],["\u003cp\u003eLeverage the REST API for quick, ad hoc testing and validation of request outputs.\u003c/p\u003e\n"]]],[],null,["# Testing is an important step in building a successful Google Ads API integration,\nwhether you're just getting started, maintaining an app, or adding\nnew features to an existing integration. This guide presents some best\npractices for testing your Google Ads API integration.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nTest accounts and production accounts\n-------------------------------------\n\n[Test accounts](/google-ads/api/docs/best-practices/test-accounts) are available for\ndevelopment purposes. With test accounts, you can validate that your application\ncode and configuration are working as intended.\n\nHowever, [not all\nfeatures](/google-ads/api/docs/best-practices/test-accounts#limitations) can be tested in a\ntest account account.\n\nWhen test account limitations prevent you from testing some features in your\nintegration, you can instead use a production account for development.\nProduction accounts for development differ from test accounts in the following\nways:\n\n- Serve ads that can be seen by users\n- Require valid URLs\n- Must comply with [advertising policies](//support.google.com/adspolicy/answer/6008942)\n\nBecause production accounts serve ads, they generate metrics letting you test\nperformance reports, as well as unlocking all the other features of the\nGoogle Ads API. However, using them for development requires extra caution. We\nrecommend taking the following measures:\n\n- Only grant access to users that need it for development purposes.\n- Set a fixed, low daily account budget.\n- Use production accounts for development only when test accounts can't be used.\n\nThus, to do full testing of your integration, you will likely need both test\ncredentials and production credentials.\n\nTest credentials\n----------------\n\nTo minimize the risk of accidentally modifying production accounts when trying\nto modify development accounts, we recommend maintaining a set of test\ncredentials that are separate from your production application credentials.\n\nTo create a set of test credentials:\n\n1. Create an email account (e.g. api.test@example.com) or a service account that will be used only for testing purposes.\n2. Add this user or service account as a valid user in the Google Ads accounts you are running your tests against. Make sure you give appropriate [access levels](//support.google.com/google-ads/answer/9978556) to this user or service account. Don't give this user or service account access to **any production accounts**.\n3. If you are using the [OAuth 2.0 user authentication flow, rather than the\n service account flow](/google-ads/api/docs/get-started/choose-application-type#choose-app-type), then generate a refresh token for your test user account.\n4. Use these new credentials when testing your application. The developer token, client ID, and client secret can be reused for testing purposes, since they have no effect in determining which Google Ads accounts can be accessed.\n\nRequest validation\n------------------\n\nIf you just need to test whether a request is valid---for example, to\nverify that the request is structured correctly and does not violate\npolicies---you can use the\n[`validate_only`](/google-ads/api/docs/concepts/api-structure#mutate_validation)\nfield, which is available for `GoogleAdsService.SearchStream` and\n`GoogleAdsService.Search` requests, as well as most mutate requests.\nConsult the [reference documentation](/google-ads/api/reference/rpc/v21/overview) to verify\nwhether this field is available for a given method.\n\nREST API\n--------\n\nFor ad hoc testing, for example to validate that a request yields the expected\noutput, using the REST API is often the easiest option. Consult the [REST\nexamples](/google-ads/api/rest/examples) to learn how to use curl in making\nrequests to the REST API. Also, try testing in the\n[REST explorer](/google-ads/api/rest/try-it)."]]