fix: resolve Instagram username via Facebook Graph API#130
Merged
Conversation
…ph.instagram.com, which rejects FB Login tokens with 'Cannot parse access token' and silently stored empty usernames
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the studio UI showing
@unknownfor connected Instagram accounts even when auth is healthy.Root cause
Our OAuth flow uses Facebook Login (
exchange_for_long_lived_token_fb), which produces an FB-flavored access token. The previous username lookup hitgraph.instagram.com/{user_id}?fields=username, which rejects those tokens with:The OAuth callback caught the resulting
WP_Errorand silently storedusername = ''. Every reauth since the FB Login switch has been broken this way, but the failure never surfaced because:@unknownin the React UI.Changes
get_username_from_token()now hitsgraph.facebook.com/v18.0/{user_id}?fields=username, which accepts both FB Login and legacy IG Basic Display tokens. Verified live: returns{"username":"extrachill"}.get_instagram_user_id_from_facebook_token()→resolve_instagram_account_from_facebook_token()— same/me/accountscall, now returnsarray{id, username}so the OAuth callback can capture the username from the call we already make. Saves a round trip on the happy path.get_username_from_token()when missing (legacy IG Basic Display tokens). Lookup failures are now logged viadatamachine_logso future regressions surface indebug.loginstead of silently rendering@unknown.Verification
Live probe against production token before merge:
Production extrachill.com account already backfilled out-of-band as a one-shot data fix; this PR ensures the next reauth (and all future reauths) populate the field correctly.
Test plan
php -lclean