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
+4 -18
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...');
console.log(`Publishing generated post to Facebook Page ID: ${META_PAGE_ID}...`);
const url = `https://graph.facebook.com/v19.0/me/feed`;
let res = await fetch(url, {
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}`);
+3 -18
View File
@@ -36,10 +36,9 @@ const message = `شركتك تحمل اسمك… وتطبيقك يحمل اسم
💬 تواصل معنا عبر واتساب: https://wa.me/962798583052`;
async function main() {
console.log('Publishing post to Facebook Page via Page Token...');
console.log(`Publishing post directly to Facebook Page ID: ${PAGE_ID}...`);
// Try direct /me/feed endpoint first (works for Page Access Token)
let res = await fetch(`https://graph.facebook.com/v19.0/me/feed`, {
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));
}