บริการแจ้งเตือน
บริการการแจ้งเตือน AFP ช่วยให้แพลตฟอร์ม AFP Direct ได้รับการแจ้งเตือนเมื่อบัญชีย่อยและเว็บไซต์มีการเปลี่ยนแปลงสถานะ แพลตฟอร์มสามารถใช้ Platform API เพื่อตรวจสอบการเปลี่ยนแปลงได้
หากต้องการรับการแจ้งเตือน ให้ใช้เซิร์ฟเวอร์ที่ยอมรับคำขอ POST และแยกวิเคราะห์เพย์โหลด JSON ที่ระบุไว้ในสคีมา (ดูตัวอย่างการตั้งค่า) จากนั้นคุณจะต้องระบุ URL ปลายทางให้กับผู้จัดการพาร์ทเนอร์เชิงกลยุทธ์เพื่อเปิดใช้งานบริการ
สคีมา
เพย์โหลดการแจ้งเตือนต้องเป็นไปตามสคีมาต่อไปนี้
{
"$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}`);
});
ตัวอย่าง URL ปลายทาง: https://yourdomain.com/your-endpoint
ตรวจสอบว่าปลายทางทํางานอยู่โดยส่งคําขอ POST โดยใช้ curl
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>