透過集合功能整理內容
你可以依據偏好儲存及分類內容。
通知服務
透過 AFP 通知服務,AFP Direct 平台可在子帳戶和網站狀態變更時收到通知。平台可以使用 Platform API 調查變更。
如要接收通知,請實作可接受 POST 要求的伺服器,並剖析 結構定義中所列的 JSON 酬載 (請參閱設定範例)。接著,您需要將端點網址提供給策略合作夥伴管理員,才能啟用服務。
結構定義
通知酬載必須遵循下列結構定義:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Notification",
"type": "object",
"properties": {
"accountName": {
"type": "string",
"description": "The name of the modified sub-account."
},
"domain": {
"type": "string",
"description": "The domain the notification refers to, if any. Optional (only populated for SITE_APPROVAL)"
},
"notificationType": {
"type": "string",
"enum": ["PUBLISHER_APPROVAL", "SITE_APPROVAL"],
"description": "Type of notification"
}
},
"required": ["platformPublisherId", "publisherId", "notificationType"],
"additionalProperties": false
}
之後可以新增更多 notificationTypes
和其他欄位。
範例
發布商核准通知的內容如下:
{
"accountName" : "platforms/pub-1234567890123456/accounts/pub-0987654321654321",
"notificationType": "PUBLISHER_APPROVAL"
}
網站核准通知如下所示:
{
"accountName" : "platforms/pub-1234567890123456/accounts/pub-0987654321654321",
"domain": "afpsite.com",
"notificationType": "SITE_APPROVAL"
}
設定範例
以下是記錄通知內容的 NodeJS 伺服器範例:
// Import express
const express = require('express');
// Create an express application
const app = express();
// Middleware to parse JSON bodies
app.use(express.json());
// Define a route to receive POST requests
app.post('/notification', (req, res) => {
console.log('Received account name:', req.body.accountName)
console.log('Received Domain:', req.body.domain)
console.log('Received notification type', req.body.notificationType)
// Send a response back to the client
res.status(200).send('Notification received');
});
// Start the server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
端點網址範例:https://yourdomain.com/your-endpoint
使用 curl
傳送 POST 要求,驗證端點是否正常運作:
curl -X POST https://yourdomain.com/your-endpoint \
-H "Content-Type: application/json" \
-d '{"accountName": "platforms/pub-1234567890123456/accounts/pub-0987654321654321", \
"notificationType": "PUBLISHER_APPROVAL"}'
確認通知服務可存取端點。通知服務會遵循網域根目錄 robots.txt
檔案中列出的指令 (如果有的話):
User-agent: GoogleOther
Disallow: <ensure your endpoint is not disallowed>
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
[null,null,[],[[["\u003cp\u003eThe AFP notification service allows AFP Direct platforms to receive notifications about sub-account and site state changes, enabling them to investigate these changes using the Platform API.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize this service, platforms need to implement a server capable of accepting POST requests and parsing a JSON payload containing information about the notification.\u003c/p\u003e\n"],["\u003cp\u003eThe notification payload includes details like account name, domain (if applicable), and notification type, with the possibility of future additions.\u003c/p\u003e\n"],["\u003cp\u003ePlatforms must provide their endpoint URL to their Strategic Partner Manager for activation and ensure their \u003ccode\u003erobots.txt\u003c/code\u003e file permits access to the endpoint by the notification service.\u003c/p\u003e\n"]]],["AFP Direct platforms receive notifications about sub-account and site state changes. To receive these, implement a server that accepts POST requests with a JSON payload, conforming to the specified schema, including `accountName`, `domain` (optional), and `notificationType`. Provide the server's endpoint URL to your Strategic Partner Manager for activation. Ensure your endpoint allows access by the notification service in your `robots.txt`. A NodeJS example and curl command are provided to demonstrate endpoint setup and testing.\n"],null,["Notification service\n--------------------\n\nThe AFP notification service lets AFP Direct platforms receive notifications\nupon [sub-account](/adsense/platforms/reference/rest/v1alpha/platforms.accounts)\nand [site](/adsense/platforms/reference/rest/v1alpha/platforms.accounts.sites)\nstate changes. Platforms can use the\n[Platform API](/adsense/platforms/api/getting-started) to investigate changes.\n\nTo receive notifications, implement a server that accepts\nPOST requests and parses the JSON payload outlined in the [schema](#schema) (see\n[example setup](#example_setup)). You then need to provide the endpoint URL\nto your Strategic Partner Manager to activate the service.\n\n### Schema\n\nThe notification payload must adhere to the following schema: \n\n {\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"title\": \"Notification\",\n \"type\": \"object\",\n \"properties\": {\n \"accountName\": {\n \"type\": \"string\",\n \"description\": \"The name of the modified sub-account.\"\n },\n \"domain\": {\n \"type\": \"string\",\n \"description\": \"The domain the notification refers to, if any. Optional (only populated for SITE_APPROVAL)\"\n },\n \"notificationType\": {\n \"type\": \"string\",\n \"enum\": [\"PUBLISHER_APPROVAL\", \"SITE_APPROVAL\"],\n \"description\": \"Type of notification\"\n }\n },\n \"required\": [\"platformPublisherId\", \"publisherId\", \"notificationType\"],\n \"additionalProperties\": false\n }\n\nMore `notificationTypes` and other fields could be added later.\n\n#### Examples\n\nA publisher approval notification would look like: \n\n {\n \"accountName\" : \"platforms/pub-1234567890123456/accounts/pub-0987654321654321\",\n \"notificationType\": \"PUBLISHER_APPROVAL\"\n }\n\nA site approval notification would look like: \n\n {\n \"accountName\" : \"platforms/pub-1234567890123456/accounts/pub-0987654321654321\",\n \"domain\": \"afpsite.com\",\n \"notificationType\": \"SITE_APPROVAL\"\n }\n\n### Example setup\n\nThe following is an example of a NodeJS server that logs the contents of a\nnotification: \n\n // Import express\n const express = require('express');\n\n // Create an express application\n const app = express();\n\n // Middleware to parse JSON bodies\n app.use(express.json());\n\n // Define a route to receive POST requests\n app.post('/notification', (req, res) =\u003e {\n console.log('Received account name:', req.body.accountName)\n console.log('Received Domain:', req.body.domain)\n console.log('Received notification type', req.body.notificationType)\n\n // Send a response back to the client\n res.status(200).send('Notification received');\n });\n\n // Start the server\n const PORT = process.env.PORT || 8080;\n app.listen(PORT, () =\u003e {\n console.log(`Server running on port ${PORT}`);\n });\n\nExample endpoint URL: `https://yourdomain.com/your-endpoint`\n\nVerify your endpoint is working by sending a POST request using `curl`: \n\n curl -X POST https://yourdomain.com/your-endpoint \\\n -H \"Content-Type: application/json\" \\\n -d '{\"accountName\": \"platforms/pub-1234567890123456/accounts/pub-0987654321654321\", \\\n \"notificationType\": \"PUBLISHER_APPROVAL\"}'\n\n### Configure robots.txt\n\nEnsure the notification service is allowed access to your endpoint. The\nnotification service respects directives outlined in the\n[`robots.txt`](https://www.robotstxt.org/robotstxt.html) file of the root of\nyour domain, if one exists: \n\n User-agent: GoogleOther\n Disallow: \u003censure your endpoint is not disallowed\u003e"]]