Dịch vụ thông báo
Dịch vụ thông báo AFP cho phép các nền tảng AFP minh bạch nhận được thông báo khi được phê duyệt PlatformChildSite, cho biết trang web hiện có trong API.
Để nhận thông báo, hãy triển khai một máy chủ chấp nhận các yêu cầu POST và phân tích cú pháp tải trọng JSON được nêu trong giản đồ (xem ví dụ về cách thiết lập). Sau đó, bạn cần cung cấp URL điểm cuối cho Nhà quản lý đối tác chiến lược để kích hoạt dịch vụ.
Lược đồ
Trọng tải thông báo phải tuân thủ giản đồ sau:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Notification",
"type": "object",
"properties": {
"platformPublisherId": {
"type": "string",
"description": "The unique identifier for the platform publisher."
},
"publisherId": {
"type": "string",
"description": "The unique identifier for the publisher."
},
"platformChildSiteName": {
"type": "string",
"description": "The name of the PlatformChildSite the notification refers to (populated for SITE_APPROVAL)."
},
"notificationType": {
"type": "string",
"enum": ["SITE_APPROVAL"],
"description": "Type of notification"
},
},
"required": ["platformPublisherId", "publisherId", "notificationType"],
"additionalProperties": false
}
Bạn có thể thêm nhiều notificationTypes
và các trường khác sau này.
Ví dụ
Thông báo SITE_APPROVAL
sẽ có dạng như sau:
{
"platformPublisherId" : "pub-123",
"publisherId" : "pub-456",
"platformChildSiteName" : "accounts/pub-123/platforms/my-platform/childAccounts/pub-456/sites/child-domain.com",
"notificationType": "SITE_APPROVAL"
}
Ví dụ về cách thiết lập
Sau đây là ví dụ về máy chủ NodeJS ghi lại nội dung của thông báo:
// 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 platformPublisherId:', req.body.platformPublisherId)
console.log('Received publisherId:', req.body.publisherId)
console.log('Received platformChildSiteName:', req.body.platformChildSiteName)
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}`);
});
URL điểm cuối mẫu: https://yourdomain.com/your-endpoint
Xác minh điểm cuối của bạn đang hoạt động bằng cách gửi yêu cầu POST bằng curl
:
curl -X POST https://yourdomain.com/your-endpoint \
-H "Content-Type: application/json" \
-d '{"platformPublisherId" : "pub-123", \
"publisherId" : "pub-456", \
"platformChildSiteName" : "accounts/pub-123/platforms/my-platform/childAccounts/pub-456/sites/child-domain.com", \
"notificationType": "SITE_APPROVAL"}'
Định cấu hình tệp robots.txt
Xác minh rằng dịch vụ thông báo được phép truy cập vào điểm cuối của bạn. Dịch vụ thông báo tuân theo các lệnh được nêu trong tệp robots.txt
của thư mục gốc của miền, nếu có:
User-agent: GoogleOther
Disallow: <ensure your endpoint is not disallowed>