fix: use user token in select-page endpoint for page listing
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions

Same bug as discover-pages: select-page was using page token to call
me/accounts, which returns empty. Now uses user_access_token from
metadata_json.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-02-19 12:22:27 +01:00
parent 21b2be1ead
commit 1cbbb6fc80

View File

@ -306,13 +306,23 @@ def oauth_select_fb_page():
oauth = OAuthService()
db = SessionLocal()
try:
# Get current user token to list pages with their page access tokens
token = oauth.get_valid_token(db, company_id, 'meta', 'facebook')
if not token:
# Need user token (not page token) to list pages with their page access tokens
from database import OAuthToken
oauth_token = db.query(OAuthToken).filter(
OAuthToken.company_id == company_id,
OAuthToken.provider == 'meta',
OAuthToken.service == 'facebook',
OAuthToken.is_active == True,
).first()
if not oauth_token:
return jsonify({'success': False, 'error': 'Brak połączenia Facebook'}), 404
meta = oauth_token.metadata_json or {}
user_token = meta.get('user_access_token') or oauth_token.access_token
from facebook_graph_service import FacebookGraphService
fb = FacebookGraphService(token)
fb = FacebookGraphService(user_token)
pages = fb.get_managed_pages()
# Find selected page