API
initialize(...)login(...)logout()reauthorize()getCurrentAccessToken()getProfile(...)logEvent(...)setAutoLogAppEventsEnabled(...)setAdvertiserTrackingEnabled(...)setAdvertiserIDCollectionEnabled(...)- Interfaces
- Type Aliases
method initialize(...)
initialize(options: Partial<FacebookConfiguration>) => Promise<void>
Initializes the Facebook JavaScript SDK on Web.
This is a no-op on Android and iOS, where the SDK is configured natively.
| Param | Type |
|---|---|
options |
<code><a href="#partial">Partial</a><<a href="#facebookconfiguration">FacebookConfiguration</a>></code> |
method login(...)
login(options: { permissions: string[]; tracking?: 'limited' | 'enabled'; nonce?: string; }) => Promise<FacebookLoginResponse>
Starts the Facebook login flow with the requested permissions.
A cancelled native login resolves without a token.
| Param | Type |
|---|---|
options |
<code>{ permissions: string[]; tracking?: 'limited' | 'enabled'; nonce?: string; }</code> |
Returns: <code>Promise<<a href="#facebookloginresponse">FacebookLoginResponse</a>></code>
method logout()
logout() => Promise<void>
Logs out the current Facebook session.
method reauthorize()
reauthorize() => Promise<FacebookLoginResponse>
Requests renewed data access for the current Facebook session.
Returns: <code>Promise<<a href="#facebookloginresponse">FacebookLoginResponse</a>></code>
method getCurrentAccessToken()
getCurrentAccessToken() => Promise<FacebookCurrentAccessTokenResponse>
Returns the current token. iOS returns an OIDC authentication token for
Limited Login. Native platforms resolve without a token when logged out;
Web rejects when there is no connected Facebook session.
Returns: <code>Promise<<a href="#facebookcurrentaccesstokenresponse">FacebookCurrentAccessTokenResponse</a>></code>
method getProfile(...)
getProfile<T extends Record<string, unknown>>(options: { fields: readonly string[]; }) => Promise<T>
Requests the selected fields from the Facebook Graph API /me endpoint.
| Param | Type |
|---|---|
options |
<code>{ fields: readonly string[]; }</code> |
Returns: <code>Promise<T></code>
method logEvent(...)
logEvent(options: { eventName: string; parameters?: Record<string, string | number>; }) => Promise<void>
Logs a Facebook App Event with optional string or number parameters.
| Param | Type |
|---|---|
options |
<code>{ eventName: string; parameters?: <a href="#record">Record</a><string, string | number>; }</code> |
method setAutoLogAppEventsEnabled(...)
setAutoLogAppEventsEnabled(options: { enabled: boolean; }) => Promise<void>
Enables or disables automatic App Event logging on native platforms.
| Param | Type |
|---|---|
options |
<code>{ enabled: boolean; }</code> |
method setAdvertiserTrackingEnabled(...)
setAdvertiserTrackingEnabled(options: { enabled: boolean; }) => Promise<void>
Enables or disables advertiser tracking on iOS.
| Param | Type |
|---|---|
options |
<code>{ enabled: boolean; }</code> |
method setAdvertiserIDCollectionEnabled(...)
setAdvertiserIDCollectionEnabled(options: { enabled: boolean; }) => Promise<void>
Enables or disables advertiser ID collection on native platforms.
| Param | Type |
|---|---|
options |
<code>{ enabled: boolean; }</code> |
Interfaces
interface FacebookConfiguration
| Prop | Type | Description |
|---|---|---|
appId |
<code>string</code> | Meta application ID. |
autoLogAppEvents |
<code>boolean</code> | Whether the Web SDK automatically logs App Events. |
xfbml |
<code>boolean</code> | Whether the Web SDK parses XFBML social plugins. |
version |
<code>string</code> | Facebook Graph API version used by the Web SDK. Defaults to v26.0. |
locale |
<code>string</code> | Locale used to load the Web SDK. Defaults to en_US. |
interface FacebookLoginResponse
| Prop | Type | Description |
|---|---|---|
accessToken |
<code><a href="#accesstoken">AccessToken</a> | null</code> | Token response when one is returned by the platform. |
recentlyGrantedPermissions |
<code>string[]</code> | Permissions granted during this login. |
recentlyDeniedPermissions |
<code>string[]</code> | Permissions denied during this login. |
interface AccessToken
| Prop | Type | Description |
|---|---|---|
applicationId |
<code>string</code> | Meta application ID that issued the token. |
declinedPermissions |
<code>string[]</code> | Permissions declined by the user. |
expires |
<code>string</code> | ISO 8601 token expiration date. |
isExpired |
<code>boolean</code> | Whether the token is expired. |
lastRefresh |
<code>string</code> | ISO 8601 date when the token was last refreshed. |
permissions |
<code>string[]</code> | Permissions granted to the token. |
token |
<code>string</code> | Token string returned by the platform. With iOS Limited Login, this is an OIDC authentication token (JWT), not a Graph API access token. |
userId |
<code>string</code> | Facebook user ID associated with the token. |
interface FacebookCurrentAccessTokenResponse
| Prop | Type | Description |
|---|---|---|
accessToken |
<code><a href="#accesstoken">AccessToken</a> | null</code> | Current token response when one is returned by the platform. |
Type Aliases
type alias Partial
Make all properties in T optional
<code>{
[P in keyof T]?: T[P];
}</code>
type alias Record
Construct a type with a set of properties K of type T
<code>{
[P in K]: T;
}</code>