// Quick connection test: node connector/scripts/test-meta.js import * as meta from "../src/meta.js"; const line = (s = "") => console.log(s); try { const me = await meta.graph("me", { fields: "id,name" }); line(`✔ Token works. Logged in as system user: ${me.name} (${me.id})\n`); const accts = await meta.listAccounts(); if (!accts.length) { line("⚠ The token works but no Pages are assigned to the system user."); line(" Business Settings → System users → social-agent → Assign assets → Pages."); process.exit(0); } line(`✔ ${accts.length} Page(s) connected:\n`); for (const a of accts) { line(` • ${a.page_name} (page ${a.page_id})`); line(a.instagram ? ` Instagram: @${a.instagram.username} — ${a.instagram.followers_count ?? "?"} followers, ${a.instagram.media_count ?? "?"} posts` : " Instagram: not linked to this Page"); } const first = accts.find((a) => a.instagram) || accts[0]; line(`\n— Sample insights for ${first.page_name} (last 28 days) —`); try { const fb = await meta.pageInsights(first, { sinceDays: 28 }); line(` Facebook: ${fb.page.followers_count ?? "?"} followers`); for (const [k, v] of Object.entries(fb.totals)) line(` ${k}: ${v}`); if (Object.keys(fb.errors).length) line(` (unavailable: ${Object.keys(fb.errors).join(", ")})`); } catch (e) { line(` Facebook insights failed: ${e.message}`); } if (first.instagram) { try { const ig = await meta.igAccountInsights(first.instagram.id, { sinceDays: 28 }); line(` Instagram @${ig.profile.username}: ${ig.profile.followers_count} followers`); for (const [k, v] of Object.entries(ig.totals)) line(` ${k}: ${v}`); if (Object.keys(ig.errors).length) line(` (unavailable: ${Object.keys(ig.errors).join(", ")})`); const media = await meta.igRecentMedia(first.instagram.id, { limit: 3 }); line(` Last ${media.length} posts:`); for (const m of media) line(` ${m.timestamp.slice(0, 10)} ${m.media_product_type} reach ${m.insights?.reach ?? "?"} views ${m.insights?.views ?? "?"} likes ${m.like_count ?? "?"}`); } catch (e) { line(` Instagram insights failed: ${e.message}`); } } line("\nAll good. You can now use the connector from Claude."); } catch (e) { line(`✘ ${e.message}`); if (e.meta?.code === 190) line(" The token is invalid or expired. Generate a new one for social-agent."); if (e.meta?.code === 10 || e.meta?.code === 200) line(" A permission is missing. Regenerate the token with all pages_* / instagram_* / read_insights permissions ticked."); process.exit(1); }