Skip to main content
Hayon connects to Facebook via Meta’s Graph API v24.0 using an OAuth 2.0 flow. The connection is Page-based: Hayon stores a Page access token rather than a personal user token, which is required for publishing content to a Facebook Page.
Connecting Facebook also automatically connects a linked Instagram Business account if one is associated with your Facebook Page. Both accounts share the same OAuth flow and are disconnected together.

How the Facebook OAuth flow works

1

Initiate the connection

Hayon’s backend (GET /api/platform/facebook/connect) builds a Facebook OAuth URL targeting https://www.facebook.com/v24.0/dialog/oauth with the required scopes and your Hayon user ID in the state parameter. The URL is returned to the frontend.
2

Authorize on Facebook

You are redirected to Facebook’s authorization dialog. Review the requested permissions (listed below) and click Continue as [your name].
3

Callback

Facebook redirects back to GET /api/platform/facebook/callback with a one-time authorization code and your user ID in state.
4

Short-lived token exchange

Hayon exchanges the code for a short-lived user access token via GET https://graph.facebook.com/v24.0/oauth/access_token.
5

Long-lived token exchange

Hayon immediately exchanges the short-lived token for a long-lived token (valid ~60 days) using the fb_exchange_token grant type.
6

Page token retrieval

Hayon calls GET /me/accounts with the long-lived token to retrieve your Facebook Pages. It selects the first Page and stores that Page’s own access token (Page tokens do not expire as long as the user token they were generated from remains valid).
7

Instagram Business account check

Hayon queries the Page for a linked instagram_business_account. If one exists, the Instagram account is also connected and stored alongside the Facebook connection.
8

Redirect to settings

You are redirected back to /settings where the connected Page (and Instagram account, if found) are shown.

Required permissions (OAuth scopes)

Hayon requests the following Facebook permissions during the OAuth flow:
ScopePurpose
public_profileRead your name and profile picture
pages_show_listList the Facebook Pages you manage
pages_read_engagementRead engagement data on Pages
pages_manage_postsPublish and manage posts on Pages
pages_manage_metadataRead Page metadata
business_managementAccess business accounts
instagram_basicAccess basic Instagram profile data
instagram_content_publishPublish content to Instagram
instagram_manage_insightsRead Instagram analytics
Facebook requires that your app has been through Meta’s App Review process before it can request most of these scopes from users who are not app admins/testers. During development, only users added as testers or admins on your Meta App can authorize successfully.

Connecting a Facebook Page

The connection always targets a Facebook Page, not your personal profile. Requirements:
  • You must be an admin of at least one Facebook Page.
  • The Page must not be restricted by Meta’s policies.
  • For Instagram connection, the Instagram account must be a Business or Creator account linked to the Facebook Page in your Meta Business Suite.
Hayon connects to the first Page returned by GET /me/accounts. If you manage multiple Pages and want a different Page connected, ensure the intended Page appears first in your Facebook account, or disconnect and reconnect after reordering.

What Hayon stores

Facebook

FieldDescription
platformIdPage ID (or user ID if no Page found)
auth.accessTokenPage access token
auth.expiresAtApproximately 60 days from connection time
profile.displayNamePage name
profile.handlePage username (if set)
profile.avatarPage profile picture URL

Instagram (if linked)

FieldDescription
platformIdInstagram Business account ID
auth.accessTokenLong-lived user access token
linkedPageIdID of the associated Facebook Page
businessIdInstagram Business account ID
profile.handleInstagram username
profile.displayNameInstagram display name

Supported post types

Content typeSupported
Text-only postsYes
Photo posts (single image)Yes
Photo posts (multiple images)Yes
Link posts (URL with preview)Yes
Video postsNo
StoriesNo
ReelsNo
EventsNo

Media requirements

  • Image formats: JPEG, PNG, GIF (static), WebP.
  • Maximum image size: 4 MB for photos published via the Graph API.
  • Maximum images per post: Up to 10 images in a multi-photo post.
  • Aspect ratio: Facebook recommends 1.91:1 for link images and 1:1 for standard photos.
  • Video: Video publishing is not currently implemented in Hayon’s Facebook integration.

Token expiry and refresh

Facebook long-lived tokens expire after approximately 60 days if not refreshed. Hayon stores the expiry timestamp in auth.expiresAt. When the health status shows expired or needsReconnection: true, you need to disconnect and reconnect your Facebook account. To manually refresh profile data while the token is still valid:
GET /api/platform/facebook/refresh
Authorization: Bearer <hayon-jwt>
This re-fetches the Page profile and linked Instagram profile using the stored Page access token.

Disconnecting

To disconnect Facebook (and the linked Instagram account), navigate to Settings > Connected accounts and click Disconnect next to Facebook, or call:
DELETE /api/platform/facebook/disconnect
Authorization: Bearer <hayon-jwt>
Disconnecting Facebook also disconnects the linked Instagram Business account because both were authorized in the same OAuth flow. If you want to keep Instagram connected, you cannot disconnect only Facebook.
Disconnecting clears all tokens and profile data for both Facebook and Instagram and sets connected: false for both. To fully revoke Hayon’s access on Meta’s side, visit https://www.facebook.com/settings?tab=applications and remove the Hayon app.

Troubleshooting

If you have no Pages or are not an admin on any Page, Hayon falls back to storing your personal user profile (with platformId set to your Facebook user ID). Publishing to personal profiles is restricted by Meta — you need a Page.
Instagram is only connected if your Facebook Page has a linked Instagram Business or Creator account. Go to your Facebook Page settings and link your Instagram account under Linked accounts, then disconnect and reconnect Facebook in Hayon.
Long-lived tokens are valid for ~60 days. After expiry, the health status shows expired. Disconnect and reconnect to obtain a new token.
If you did not grant all requested permissions during the Facebook authorization dialog, some features may not work. Disconnect and reconnect, granting all permissions when prompted.

Build docs developers (and LLMs) love