การแมปหน่วยโฆษณา
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
การแมปหน่วยโฆษณาคือการกําหนดค่าของบุคคลที่สามซึ่งแมปกับหน่วยโฆษณา AdMob และช่วยให้หน่วยโฆษณาส่งคําขอโฆษณาไปยังเครือข่ายโฆษณาของบุคคลที่สามได้
เมื่อสร้างกลุ่มสื่อกลาง ระบบจะใช้การแมปหน่วยโฆษณาเป็นพารามิเตอร์สําหรับบรรทัดกลุ่มสื่อกลางแต่ละรายการ เพื่อเป็นการตั้งค่าสําหรับหน่วยโฆษณาที่ระบุเพื่อส่งคําขอเครือข่ายโฆษณาของบุคคลที่สาม
คุณต้องสร้างการแมปหน่วยโฆษณาแยกต่างหากนอกกลุ่มสื่อกลางและบรรทัดกลุ่มสื่อกลาง ซึ่งต่างจากใน UI ของ AdMob
หลังจากสร้างแล้ว คุณสามารถแสดงรายการการแมปหน่วยโฆษณาทั้งหมดและใช้เป็นการพารามิเตอร์เมื่อสร้างหรืออัปเดตบรรทัดกลุ่มสื่อกลางด้วยการแมปหน่วยโฆษณาใหม่
ตัวอย่าง
เมื่อสร้างข้อมูลเข้าสู่ระบบ OAuth 2.0 แล้ว คุณก็พร้อมเริ่มใช้ AdMob API หากต้องการขอสิทธิ์โดยใช้ OAuth 2.0 แอปพลิเคชันของคุณจะต้องมีข้อมูลขอบเขตด้วย
ข้อมูลขอบเขต OAuth 2.0 มีดังนี้
ขอบเขต |
ความหมาย |
https://www.googleapis.com/auth/admob.monetization |
ดู สร้าง และแก้ไขการตั้งค่าการสร้างรายได้จาก AdMob
|
https://www.googleapis.com/auth/admob.readonly |
ดูข้อมูล AdMob ทั้งหมด ข้อมูลนี้อาจรวมถึงข้อมูลบัญชี การตั้งค่าพื้นที่โฆษณาและสื่อกลาง รายงาน และข้อมูลอื่นๆ
แต่ไม่รวมข้อมูลที่ละเอียดอ่อน เช่น การชำระเงินหรือรายละเอียดของแคมเปญ
|
เริ่มต้นสร้างการแมปหน่วยโฆษณาแรกโดยทำดังนี้
curl (บรรทัดคำสั่ง)
คำขอที่ใช้ curl
โหลดไฟล์รหัสลับไคลเอ็นต์และสร้างข้อมูลเข้าสู่ระบบการให้สิทธิ์
ครั้งแรกที่ทำขั้นตอนนี้ ระบบจะขอให้คุณยอมรับพรอมต์การให้สิทธิ์ในเบราว์เซอร์ ก่อนยอมรับ โปรดตรวจสอบว่าคุณได้ลงชื่อเข้าใช้ด้วยบัญชี Google ที่มีสิทธิ์เข้าถึง AdMob API แอปพลิเคชันของคุณจะได้รับสิทธิ์เข้าถึงข้อมูลในนามของบัญชีที่เข้าสู่ระบบอยู่
สำหรับการตรวจสอบสิทธิ์และการให้สิทธิ์ เราขอแนะนำให้ใช้ oauth2l ซึ่งเป็นเครื่องมือบรรทัดคำสั่งง่ายๆ สำหรับการทำงานกับ Google OAuth 2.0 ติดตั้ง oauth2l แล้วเรียกใช้คำสั่งด้านล่าง โดยแทนที่ path_to_credentials_json ด้วยเส้นทางไปยังไฟล์ credentials.json
ที่คุณดาวน์โหลดเมื่อลงทะเบียนแอปพลิเคชันที่อยู่ในระบบคลาวด์ สำหรับการเรียกใช้ครั้งแรก คำสั่งดังกล่าวจะนำคุณสู่ขั้นตอนการให้สิทธิ์ OAuth 2.0 การเรียกใช้ครั้งต่อๆ ไปจะรีเฟรชโทเค็นโดยอัตโนมัติ
oauth2l header --json path_to_credentials_json --scope admob.readonly,admob.monetization
แสดงรายการแหล่งที่มาของโฆษณา
รับข้อมูลแหล่งที่มาของโฆษณา AdMob โดยแทนที่ pub-XXXXXXXXXXXXXXXX
ด้วยรหัสผู้เผยแพร่โฆษณา ดูวิธีการค้นหารหัสผู้เผยแพร่โฆษณา
curl --http1.0 -X GET https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/adSources \
-H "$(oauth2l header --json path_to_credentials_json --scope admob.readonly)"
ตัวอย่างคำตอบ
{
"adSources": [
{
"name": "accounts/pub-XXXXXXXXXXXXXXXX/adSources/5450213213286189855",
"adSourceId": "5450213213286189855",
"title": "AdMob Network",
}
]
}
แสดงรายการอะแดปเตอร์
แทนที่ SSSSSSSSSSSSSSSSSSSS ด้วยรหัสแหล่งที่มาของโฆษณาสำหรับอะแดปเตอร์ที่สนใจ
ใช้คำสั่งต่อไปนี้เพื่อดูรายการอะแดปเตอร์
curl --http1.0 -X GET https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/adSources/SSSSSSSSSSSSSSSSSSSS/adapters \
-H "$(oauth2l header --json path_to_credentials_json --scope admob.readonly)"
ตัวอย่างการตอบกลับสําหรับแหล่งที่มาของโฆษณาเครือข่าย AdMob ที่มีรหัส
5450213213286189855
{
"adapters": [
{
"name": "accounts/pub-XXXXXXXXXXXXXXXX/adSources/5450213213286189855/adapters/1",
"adapterId": "1",
"title": "AdMob Network Android SDK",
"platform": "ANDROID",
"formats": ["BANNER", "INTERSTITIAL",
"REWARDED", "NATIVE", "REWARDED_INTERSTITIAL", "APP_OPEN"],
"adapterConfigMetadata": [{
"adapterConfigMetadataId": "118",
"adapterConfigMetadataLabel": "Ad unit ID"
}]
},
{
"name": "accounts/pub-XXXXXXXXXXXXXXXX/adSources/5450213213286189855/adapters/2",
"adapterId": "2",
"title": "AdMob Network iOS SDK",
"platform": "ANDROID",
"formats": ["BANNER", "INTERSTITIAL",
"REWARDED", "NATIVE", "REWARDED_INTERSTITIAL", "APP_OPEN"],
"adapterConfigMetadata": [{
"adapterConfigMetadataId": "119",
"adapterConfigMetadataLabel": "Ad unit ID"
}]
}]
}
สร้างการแมปหน่วยโฆษณา
แทนที่ YYYYYYYYYY ด้วยข้อมูลโค้ดเศษของรหัสหน่วยโฆษณา ส่วนของรหัสหน่วยโฆษณาคือตัวเลข 10 หลักสุดท้ายของรหัสหน่วยโฆษณาซึ่งอยู่ในรูปแบบ "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY" ดูวิธีการค้นหารหัสหน่วยโฆษณา
curl --http1.0 -X POST \
https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings \
-H "$(oauth2l header --json path_to_credentials_json --scope admob.monetization)" \
-H "Content-Type: application/json" --data @- << EOF
{
"name": "InMobi ad unit mapping",
"adapterId": "8",
"adUnitConfigurations": {
"174": "inMobiAccountId",
"176": "inMobiPlacementId"
}
}
EOF
แสดงรายการการแมปหน่วยโฆษณาทั้งหมด
แทนที่ YYYYYYYYYY ด้วยข้อมูลโค้ดเศษของรหัสหน่วยโฆษณา ส่วนของรหัสหน่วยโฆษณาคือตัวเลข 10 หลักสุดท้ายของรหัสหน่วยโฆษณาจากรูปแบบ "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY" ดูวิธีการค้นหารหัสหน่วยโฆษณา
curl --http1.0 -X GET \
https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings \
-H "$(oauth2l header --json path_to_credentials_json --scope admob.readonly)"
{
"adUnitMappingName":
"accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings/ZZZZZZZZZZ"
{
"adapterId": "1",
"state": "ENABLED",
"adUnitConfigurations": {
"adUnitMappingConfigurationKey": "adUnitId",
"adUnitMappingConfigurationValue": "118",
}
}
}
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\u003cp\u003eAd unit mappings link your AdMob ad units to third-party ad networks, allowing them to request ads from those networks.\u003c/p\u003e\n"],["\u003cp\u003eThese mappings are crucial for mediation groups, directing specific ad units to make requests from external ad sources.\u003c/p\u003e\n"],["\u003cp\u003eUnlike the AdMob UI, you must create and manage ad unit mappings separately through the AdMob API.\u003c/p\u003e\n"],["\u003cp\u003eOnce created, you can utilize these mappings when establishing or modifying mediation group lines.\u003c/p\u003e\n"],["\u003cp\u003eYou can get started with AdMob API by creating OAuth 2.0 credentials and generating authorization credentials using your client secret file.\u003c/p\u003e\n"]]],["Ad unit mappings are configured settings for third-party ad networks. They are created independently of mediation groups and their lines, and are used as parameters within those lines to facilitate ad requests. To use, first generate OAuth 2.0 credentials. Then, list ad sources and adapters, obtain the ad unit ID fragment, and create the ad unit mapping via a POST request. Finally, list the newly created mapping via a GET request.\n"],null,["# Ad unit mappings are third-party configuration settings that map to an AdMob ad\nunit and enable it to make an ad request to a third-party ad network.\n\nWhen creating a mediation group, ad unit mappings are used as a parameter for\neach [mediation group line](/admob/api/reference/rest/v1beta/accounts.mediationGroups)\nas settings for the specified ad unit to make third-party ad network requests.\nUnlike on the AdMob UI, ad unit mappings need to be [created](/admob/api/reference/rest/v1beta/accounts.adUnits.adUnitMappings/create)\nindependently outside of mediation groups and mediation group lines.\nAfter creation, you can [list](/admob/api/reference/rest/v1beta/accounts.adUnits.adUnitMappings/list)\nall ad unit mappings and use them as a parameter when creating or updating\nmediation group lines with new ad unit mappings.\n\nExamples\n--------\n\nWith [OAuth 2.0 credentials created](/admob/api/v1/getting-started#credentials),\nyou're ready to start using the AdMob API. To request access using OAuth\n2.0, your application will also need the scope information.\n\nHere's the OAuth 2.0 scope information:\n\n\u003cbr /\u003e\n\n| Scope | Meaning |\n|------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `https://www.googleapis.com/auth/admob.monetization` | See, create, and edit your AdMob monetization settings. |\n| `https://www.googleapis.com/auth/admob.readonly` | See all AdMob data. This may include account information, inventory and mediation settings, reports, and other data. This doesn't include sensitive data, such as payments or campaign details. |\n\n\u003cbr /\u003e\n\nGet started on creating your first ad unit mapping: \n\n### curl (command line)\n\n### Requests using curl\n\n1. Load the [client secrets file](https://console.cloud.google.com/apis/credentials) and generate authorization credentials.\n\n The first time you perform this step you'll be asked to accept an\n authorization prompt in your browser. Before accepting, make sure you're\n signed in with a Google Account that has access to the AdMob API. Your\n application will be authorized to access data on behalf of whichever\n account is currently logged in.\n\n For authentication and authorization, we recommend using\n [oauth2l](//github.com/google/oauth2l), a simple command-line tool for\n working with Google OAuth 2.0. Install oauth2l and run the\n command below, replacing \u003cvar translate=\"no\"\u003epath_to_credentials_json\u003c/var\u003e with a path\n to a `credentials.json` file that you download when registering your\n cloud application. For the first run, the command walks you through the\n OAuth 2.0 authorization flow. Subsequent runs refresh the token\n automatically. \n\n ```\n oauth2l header --json path_to_credentials_json --scope admob.readonly,admob.monetization\n ```\n2. List ad sources.\n\n Get AdMob ad source information by replacing \u003cvar translate=\"no\"\u003epub-XXXXXXXXXXXXXXXX\u003c/var\u003e\n with your publisher ID. See the\n [instructions](//support.google.com/admob/answer/2784578) on how to find\n your publisher ID. \n\n ```\n curl --http1.0 -X GET https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/adSources \\\n -H \"$(oauth2l header --json path_to_credentials_json --scope admob.readonly)\"\n ```\n\n Sample response: \n\n ```text\n {\n \"adSources\": [\n {\n \"name\": \"accounts/pub-XXXXXXXXXXXXXXXX/adSources/5450213213286189855\",\n \"adSourceId\": \"5450213213286189855\",\n \"title\": \"AdMob Network\",\n }\n ]\n }\n ```\n3. List the adapters.\n\n Replace \u003cvar translate=\"no\"\u003eSSSSSSSSSSSSSSSSSSSS\u003c/var\u003e with the ad source ID for the\n adapters of interest.\n\n Use the following command to get a list of adapters: \n\n ```\n curl --http1.0 -X GET https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/adSources/SSSSSSSSSSSSSSSSSSSS/adapters \\\n -H \"$(oauth2l header --json path_to_credentials_json --scope admob.readonly)\"\n ```\n\n Sample response for the AdMob Network ad source with ID\n `5450213213286189855`: \n\n ```scdoc\n {\n \"adapters\": [\n {\n \"name\": \"accounts/pub-XXXXXXXXXXXXXXXX/adSources/5450213213286189855/adapters/1\",\n \"adapterId\": \"1\",\n \"title\": \"AdMob Network Android SDK\",\n \"platform\": \"ANDROID\",\n \"formats\": [\"BANNER\", \"INTERSTITIAL\",\n \"REWARDED\", \"NATIVE\", \"REWARDED_INTERSTITIAL\", \"APP_OPEN\"],\n \"adapterConfigMetadata\": [{\n \"adapterConfigMetadataId\": \"118\",\n \"adapterConfigMetadataLabel\": \"Ad unit ID\"\n }]\n },\n {\n \"name\": \"accounts/pub-XXXXXXXXXXXXXXXX/adSources/5450213213286189855/adapters/2\",\n \"adapterId\": \"2\",\n \"title\": \"AdMob Network iOS SDK\",\n \"platform\": \"ANDROID\",\n \"formats\": [\"BANNER\", \"INTERSTITIAL\",\n \"REWARDED\", \"NATIVE\", \"REWARDED_INTERSTITIAL\", \"APP_OPEN\"],\n \"adapterConfigMetadata\": [{\n \"adapterConfigMetadataId\": \"119\",\n \"adapterConfigMetadataLabel\": \"Ad unit ID\"\n }]\n }]\n }\n ```\n4. Create an ad unit mapping.\n\n Replace \u003cvar translate=\"no\"\u003eYYYYYYYYYY\u003c/var\u003e with your ad unit ID fragment. The ad unit\n ID fragment is the last 10 digits of your ad unit ID which follows\n the format \"ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY\". See instructions to\n [find your ad unit ID](//support.google.com/admob/answer/7356431). \n\n ```\n curl --http1.0 -X POST \\\n https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings \\\n -H \"$(oauth2l header --json path_to_credentials_json --scope admob.monetization)\" \\\n -H \"Content-Type: application/json\" --data @- \u003c\u003c EOF\n {\n \"name\": \"InMobi ad unit mapping\",\n \"adapterId\": \"8\",\n \"adUnitConfigurations\": {\n \"174\": \"inMobiAccountId\",\n \"176\": \"inMobiPlacementId\"\n }\n }\n EOF\n ```\n5. List all ad unit mappings.\n\n Replace \u003cvar translate=\"no\"\u003eYYYYYYYYYY\u003c/var\u003e with your ad unit ID fragment. The ad unit\n ID fragment is the last 10 digits of your ad unit ID from\n the format \"ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY\". See instructions to\n [find your ad unit ID](//support.google.com/admob/answer/7356431). \n\n ```\n curl --http1.0 -X GET \\\n https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings \\\n -H \"$(oauth2l header --json path_to_credentials_json --scope admob.readonly)\"\n ``` \n\n ```text\n {\n \"adUnitMappingName\":\n \"accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings/ZZZZZZZZZZ\"\n {\n \"adapterId\": \"1\",\n \"state\": \"ENABLED\",\n \"adUnitConfigurations\": {\n \"adUnitMappingConfigurationKey\": \"adUnitId\",\n \"adUnitMappingConfigurationValue\": \"118\",\n }\n }\n }\n ```"]]