Direct PAGE_ID/feed endpoint update

This commit is contained in:
Hamza-Ayed
2026-07-24 16:51:33 +03:00
parent b47102f36b
commit 0b9dca5d75
2 changed files with 9 additions and 38 deletions
+5 -19
View File
@@ -84,10 +84,10 @@ async function generatePostWithGemini(topic = 'منشور تعريفي عن من
* Publish generated post to Meta Facebook Page
*/
async function publishToFacebook(message) {
console.log('Publishing generated post to Facebook Page...');
const url = `https://graph.facebook.com/v19.0/me/feed`;
let res = await fetch(url, {
console.log(`Publishing generated post to Facebook Page ID: ${META_PAGE_ID}...`);
const url = `https://graph.facebook.com/v19.0/${META_PAGE_ID}/feed`;
const res = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
@@ -96,21 +96,7 @@ async function publishToFacebook(message) {
})
});
let data = await res.json();
if (data.error && META_PAGE_ID) {
console.log('Direct /me/feed returned error, fallback to Page ID endpoint:', META_PAGE_ID);
const fallbackUrl = `https://graph.facebook.com/v19.0/${META_PAGE_ID}/feed`;
res = await fetch(fallbackUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
access_token: META_ACCESS_TOKEN,
message: message
})
});
data = await res.json();
}
const data = await res.json();
if (data.error) {
throw new Error(`Meta Graph API Error [${data.error.code}]: ${data.error.message}`);