使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
通知服务
借助 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>
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。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"]]