fix: store PAGE token in SocialMediaConfig for reliable publishing
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
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
- select-page now saves page token to SocialMediaConfig.access_token - _get_publish_token prefers config page token over OAuthToken - Prevents breakage when OAuth reconnect overwrites OAuthToken with USER token Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6d1dfd2d4d
commit
8f689dd4b9
@ -373,6 +373,7 @@ def oauth_select_fb_page():
|
||||
|
||||
config.page_id = str(page_id)
|
||||
config.page_name = page_name
|
||||
config.access_token = page_access_token # PAGE token for publishing
|
||||
config.is_active = True
|
||||
config.debug_mode = True
|
||||
config.updated_by = current_user.id
|
||||
|
||||
@ -384,8 +384,8 @@ class SocialPublisherService:
|
||||
def _get_publish_token(self, db, publishing_company_id: int) -> Tuple[Optional[str], Optional[SocialMediaConfig]]:
|
||||
"""Get access token and config for publishing.
|
||||
|
||||
Tries OAuth token first (from oauth_tokens table), falls back to
|
||||
manual token in social_media_config.
|
||||
Uses page token from social_media_config (set by select-page).
|
||||
Falls back to OAuth token if config token is missing.
|
||||
"""
|
||||
config = db.query(SocialMediaConfig).filter(
|
||||
SocialMediaConfig.platform == 'facebook',
|
||||
@ -396,7 +396,11 @@ class SocialPublisherService:
|
||||
if not config or not config.page_id:
|
||||
return None, None
|
||||
|
||||
# Try OAuth token first
|
||||
# Prefer page token from config (guaranteed PAGE type, set by select-page)
|
||||
if config.access_token:
|
||||
return config.access_token, config
|
||||
|
||||
# Fallback to OAuth token (may be USER token — works for reading, not always for publishing)
|
||||
from oauth_service import OAuthService
|
||||
oauth = OAuthService()
|
||||
oauth_token = oauth.get_valid_token(db, publishing_company_id, 'meta', 'facebook')
|
||||
@ -404,10 +408,6 @@ class SocialPublisherService:
|
||||
if oauth_token:
|
||||
return oauth_token, config
|
||||
|
||||
# Fallback to manual token in config
|
||||
if config.access_token:
|
||||
return config.access_token, config
|
||||
|
||||
return None, None
|
||||
|
||||
def publish_post(self, post_id: int, force_live: bool = False) -> Tuple[bool, str]:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user