diff --git a/scripts/ai-post-generator.js b/scripts/ai-post-generator.js index 8aa07ac..8d19ed2 100644 --- a/scripts/ai-post-generator.js +++ b/scripts/ai-post-generator.js @@ -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}`); diff --git a/scripts/publish-now.js b/scripts/publish-now.js index f4c4a62..1e64dc0 100644 --- a/scripts/publish-now.js +++ b/scripts/publish-now.js @@ -36,10 +36,9 @@ const message = `شركتك تحمل اسمك… وتطبيقك يحمل اسم 💬 تواصل معنا عبر واتساب: https://wa.me/962798583052`; async function main() { - console.log('Publishing post to Facebook Page via Page Token...'); - - // Try direct /me/feed endpoint first (works for Page Access Token) - let res = await fetch(`https://graph.facebook.com/v19.0/me/feed`, { + console.log(`Publishing post directly to Facebook Page ID: ${PAGE_ID}...`); + + const res = await fetch(`https://graph.facebook.com/v19.0/${PAGE_ID}/feed`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ @@ -48,21 +47,7 @@ async function main() { }) }); - let data = await res.json(); - - if (data.error && PAGE_ID) { - console.log('Direct /me/feed failed, trying Page ID endpoint:', PAGE_ID); - res = await fetch(`https://graph.facebook.com/v19.0/${PAGE_ID}/feed`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - access_token: USER_TOKEN, - message: message - }) - }); - data = await res.json(); - } - + const data = await res.json(); console.log('Response from Meta:', JSON.stringify(data, null, 2)); }