سرویس اطلاع رسانی
سرویس اعلان AFP به پلتفرمهای AFP Direct اجازه میدهد در صورت تغییر حساب فرعی و وضعیت سایت ، اعلانها را دریافت کنند. پلتفرمها میتوانند از پلتفرم 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}`);
});
نشانی اینترنتی نقطه پایانی مثال: 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>