通知服务
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
确保允许通知服务访问您的端点。通过
通知服务会遵循
robots.txt
文件的以下路径:
您的域名(如果存在):
User-agent: GoogleOther
Disallow: <ensure your endpoint is not disallowed>