Skip to content

Fix Facebook/Instagram Page fetch missing New Pages Experience pages - #292

Open
StoriaJames wants to merge 2 commits into
trypostit:mainfrom
Storia-Technologies:upstream-facebook-fix
Open

Fix Facebook/Instagram Page fetch missing New Pages Experience pages#292
StoriaJames wants to merge 2 commits into
trypostit:mainfrom
Storia-Technologies:upstream-facebook-fix

Conversation

@StoriaJames

Copy link
Copy Markdown

Summary

  • /me/accounts silently omits Pages under Meta's newer "New Pages Experience" / Business Portfolio model - confirmed via Meta's own Access Token Debugger against a live account where the token's granular scopes showed the Page was explicitly granted (pages_show_list, pages_read_engagement, pages_manage_posts all scoped to the Page's ID), yet /me/accounts returned an empty list. Querying the Page node directly by ID worked fine.
  • This surfaces to users as "No Facebook Pages found. You need to be an admin of at least one page." even though they are.
  • Added a fallback in both FacebookController::fetchPages() and InstagramFacebookController::fetchPagesWithInstagram(): when /me/accounts comes back empty, fall through to Business Manager's owned_pages/client_pages edges (via /me/businesses), using the business_management scope (already requested by the Instagram-via-Facebook flow; added to the Facebook flow's scope list in this PR).

Test plan

  • Reproduced against a live self-hosted instance: /me/accounts empty for an admin's own New Pages Experience Page, confirmed via Meta's Access Token Debugger that the grant was real and page-scoped, confirmed direct page-ID query worked.
  • Applied the fallback, rebuilt, reconnected the same account/Page - Page now found and connected successfully, published a real post through it.
  • Would appreciate a maintainer/community check against a "New Pages Experience" Page under a Business Portfolio with multiple pages, to confirm the selection flow (selectPage/select) still behaves correctly when the fallback path returns more than one Page.

(Reopened from #291, which accidentally included unrelated commits from our fork's own main branch - this one contains only the fix, based directly on upstream main.)

/me/accounts silently omits Pages that live under Meta's newer
"New Pages Experience" / Business Portfolio model, even when the
token's granular scopes show the Page was explicitly granted -
confirmed via Meta's own Access Token Debugger against a live
account whose Page returned zero results from /me/accounts but
resolved fine when queried directly by ID.

Falls back through Business Manager's owned_pages/client_pages
(via the existing business_management scope) when /me/accounts
comes back empty, so Pages under that model are still found.
Same root cause and fix as the FacebookController fetchPages()
fallback - the Page/Instagram-linked-Page lookup goes through the
same /me/accounts call and is subject to the same Meta-side gap.
Copilot AI lite review requested due to automatic review settings August 17, 2026 09:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a Meta Graph API behavior where /me/accounts can return an empty Page list for Pages under the “New Pages Experience” / Business Portfolio model, causing users to incorrectly see “No Facebook Pages found…” despite having granted page-scoped permissions. It introduces a fallback that discovers Pages via Business Manager (/me/businessesowned_pages / client_pages) when the primary /me/accounts path yields no results.

Changes:

  • Added business_management to Facebook OAuth scopes to support Business Manager-based Page discovery.
  • Implemented a fallback Page discovery path in both Facebook and Instagram-via-Facebook controllers when /me/accounts returns an empty list.
  • Deduplicated Pages returned by the Business Manager fallback by Page ID.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
app/Http/Controllers/Auth/FacebookController.php Adds business_management scope and a Business Manager fallback for Page discovery when /me/accounts returns empty.
app/Http/Controllers/Auth/InstagramFacebookController.php Adds the same fallback behavior for Instagram-via-Facebook Page discovery and centralizes Graph fields used by the page fetch.
Suppressed comments (2)

app/Http/Controllers/Auth/FacebookController.php:306

  • fetchPagesViaBusinessManager() lets /me/businesses exceptions from GraphPaginator::all() bubble up, which can turn a "no pages" situation into a hard OAuth failure (especially for older tokens missing business_management, or intermittent Graph errors). Since this method is a fallback, it should fail soft: log and return an empty list (similar to how edge lookups are handled).
        $businesses = GraphPaginator::all(
            config('trypost.platforms.facebook.graph_api').'/me/businesses',
            [
                'access_token' => $userToken,
                'fields' => 'id',
                'limit' => 100,
            ],
        );

app/Http/Controllers/Auth/InstagramFacebookController.php:293

  • fetchPagesViaBusinessManager() lets /me/businesses exceptions from GraphPaginator::all() bubble up. Because this is only a fallback path (used when /me/accounts is empty), it should fail soft (log + return []) to avoid turning an empty Page list into a hard connect error when Business Manager APIs are unavailable or the token lacks access.
        $businesses = GraphPaginator::all("{$graphApi}/me/businesses", [
            'access_token' => $userToken,
            'fields' => 'id',
            'limit' => 100,
        ]);

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +279 to +286
// /me/accounts silently omits Pages that live under Meta's newer "New
// Pages Experience" / Business Portfolio model, even when the token's
// granular scopes show the Page was explicitly granted (confirmed via
// Meta's own Access Token Debugger, 2026-08-16). Falling back through
// Business Manager's owned_pages picks those up.
if (empty($pages)) {
$pages = $this->fetchPagesViaBusinessManager($userToken);
}
Comment on lines +246 to +252
// /me/accounts silently omits Pages that live under Meta's newer "New
// Pages Experience" / Business Portfolio model (confirmed via Meta's own
// Access Token Debugger, 2026-08-16). Fall back through Business
// Manager's owned_pages/client_pages, same fix as FacebookController.
if (empty($pages)) {
$pages = $this->fetchPagesViaBusinessManager($userToken, $graphApi, $fields);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants