mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 14:20:12 +00:00
Updated types of facebook-js-sdk to version 3.1
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
|
||||
|
||||
FB.init({
|
||||
appId: '***********',
|
||||
version: 'v2.5',
|
||||
status: true,
|
||||
cookie: true,
|
||||
xfbml: true
|
||||
appId: '***********',
|
||||
version: 'v2.5',
|
||||
status: true,
|
||||
cookie: true,
|
||||
xfbml: true,
|
||||
autoLogAppEvents: false
|
||||
});
|
||||
|
||||
FB.getLoginStatus(function(response: fb.StatusResponse) {
|
||||
@@ -31,12 +30,18 @@ FB.login(function(response: fb.StatusResponse) {
|
||||
scope: 'public_profile'
|
||||
});
|
||||
|
||||
FB.login({
|
||||
scope: 'public_profile'
|
||||
});
|
||||
|
||||
FB.logout(function(response: fb.StatusResponse) {
|
||||
console.log(response);
|
||||
console.log(response.status);
|
||||
console.log(response.authResponse.accessToken);
|
||||
});
|
||||
|
||||
FB.logout();
|
||||
|
||||
/**
|
||||
* Dialog samples from Facebook documentation:
|
||||
*/
|
||||
@@ -65,8 +70,8 @@ FB.ui({
|
||||
method: 'pay',
|
||||
action: 'purchaseitem',
|
||||
product: 'YOUR_PRODUCT_URL'
|
||||
}, data => {
|
||||
console.log(data.payment_id);
|
||||
}, response => {
|
||||
console.log(response.payment_id);
|
||||
});
|
||||
|
||||
FB.ui({
|
||||
@@ -75,43 +80,93 @@ FB.ui({
|
||||
product_id: 'com.fb.friendsmash.coins.10',
|
||||
developer_payload: 'this_is_a_test_payload'
|
||||
}, response => {
|
||||
console.log(response);
|
||||
console.log(response.payment_id);
|
||||
});
|
||||
|
||||
FB.ui({
|
||||
method: 'pagetab',
|
||||
redirect_uri: 'YOUR_URL'
|
||||
}, response => {});
|
||||
}, response => {
|
||||
console.log(response.error_code);
|
||||
});
|
||||
|
||||
FB.ui({
|
||||
method: 'send',
|
||||
link: 'http://www.nytimes.com/interactive/2015/04/15/travel/europe-favorite-streets.html',
|
||||
}, response => {});
|
||||
}, response => {
|
||||
console.log(response.error_code);
|
||||
});
|
||||
|
||||
FB.ui({
|
||||
method: 'apprequests',
|
||||
message: 'Take this bomb to blast your way to victory!',
|
||||
to: 'USER_ID, USER_ID, INVITE_TOKEN',
|
||||
action_type:'send',
|
||||
action_type: 'send',
|
||||
object_id: 'YOUR_OBJECT_ID', // e.g. '191181717736427'
|
||||
}, response => {
|
||||
console.log(response);
|
||||
console.log(response.request);
|
||||
});
|
||||
|
||||
FB.ui({
|
||||
method: 'apprequests',
|
||||
message: 'Friend Smash Request!',
|
||||
filters: [
|
||||
{ name:'GROUP_1_NAME', user_ids:['USER_ID','USER_ID','USER_ID'] },
|
||||
{ name:'GROUP_2_NAME', user_ids: ['USER_ID','USER_ID','USER_ID'] },
|
||||
{ name: 'GROUP_1_NAME', user_ids: ['USER_ID', 'USER_ID', 'USER_ID'] },
|
||||
{ name: 'GROUP_2_NAME', user_ids: ['USER_ID', 'USER_ID', 'USER_ID'] },
|
||||
]
|
||||
}, response => {
|
||||
console.log(response);
|
||||
console.log(response.request);
|
||||
});
|
||||
|
||||
FB.ui({
|
||||
method: 'share',
|
||||
mobile_iframe: true,
|
||||
href: 'https://developers.facebook.com/docs/',
|
||||
picture: 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/2000px-Google_2015_logo.svg.png',
|
||||
}, response => {});
|
||||
href: 'https://developers.facebook.com/docs/'
|
||||
}, response => {
|
||||
console.log(response.post_id);
|
||||
});
|
||||
|
||||
FB.ui({
|
||||
account_id: '<ACCOUNT_ID>',
|
||||
display: 'popup',
|
||||
method: 'create_offer',
|
||||
objective: 'APP_INSTALLS',
|
||||
page_id: '<PAGE_ID>',
|
||||
}, response => {
|
||||
console.log(response.id)
|
||||
});
|
||||
|
||||
FB.ui({
|
||||
account_id: '<ACCOUNT_ID>',
|
||||
display: 'popup',
|
||||
method: 'lead_gen',
|
||||
page_id: '<PAGE_ID>',
|
||||
}, response => {
|
||||
console.log(response.formID)
|
||||
});
|
||||
|
||||
FB.ui({
|
||||
display: 'popup',
|
||||
method: 'canvas_editor',
|
||||
business_id: '<BUSINESS_ID>',
|
||||
page_id: '<PAGE_ID>'
|
||||
}, response => {
|
||||
console.log(response.id)
|
||||
});
|
||||
|
||||
FB.ui({
|
||||
display: 'popup',
|
||||
method: 'canvas_editor',
|
||||
account_id: '<AD_ACCOUNT_ID>',
|
||||
business_id: '<BUSINESS_ID>',
|
||||
page_id: '<PAGE_ID>',
|
||||
template_id: '<TEMPLATE_ID>'
|
||||
}, response => {
|
||||
console.log(response.id)
|
||||
});
|
||||
|
||||
FB.ui({
|
||||
display: 'popup',
|
||||
method: 'canvas_preview',
|
||||
canvas_id: '<CANVAS_ID>'
|
||||
});
|
||||
|
||||
202
types/facebook-js-sdk/index.d.ts
vendored
202
types/facebook-js-sdk/index.d.ts
vendored
@@ -1,14 +1,15 @@
|
||||
// Type definitions for the Facebook Javascript SDK 2.8
|
||||
// Type definitions for the Facebook Javascript SDK 3.1
|
||||
// Project: https://developers.facebook.com/docs/javascript
|
||||
// Definitions by: Amrit Kahlon <https://github.com/amritk>
|
||||
// Mahmoud Zohdi <https://github.com/mahmoudzohdi>
|
||||
// Marc Knaup <https://github.com/fluidsonic>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import fb = facebook;
|
||||
declare var FB: fb.FacebookStatic;
|
||||
declare namespace facebook {
|
||||
|
||||
|
||||
|
||||
|
||||
interface FacebookStatic {
|
||||
api: any;
|
||||
AppEvents: any;
|
||||
@@ -19,24 +20,26 @@ declare namespace facebook {
|
||||
* The method FB.getAuthResponse() is a synchronous accessor for the current authResponse.
|
||||
* The synchronous nature of this method is what sets it apart from the other login methods.
|
||||
*
|
||||
* @param callback function to handle the response.
|
||||
*
|
||||
* This method is similar in nature to FB.getLoginStatus(), but it returns just the authResponse object.
|
||||
*/
|
||||
getAuthResponse(): AuthResponse;
|
||||
getAuthResponse(): AuthResponse | null;
|
||||
|
||||
/**
|
||||
* FB.getLoginStatus() allows you to determine if a user is
|
||||
* logged in to Facebook and has authenticated your app.
|
||||
*
|
||||
* @param callback function to handle the response.
|
||||
* @param roundtrip force a roundtrip to Facebook - effectively refreshing the cache of the response object
|
||||
*/
|
||||
getLoginStatus(callback: (response: StatusResponse) => void, roundtrip?: boolean ): void;
|
||||
getLoginStatus(callback: (response: StatusResponse) => void, roundtrip?: boolean): void;
|
||||
|
||||
/**
|
||||
* The method FB.init() is used to initialize and setup the SDK.
|
||||
*
|
||||
* @param params params for the initialization.
|
||||
*/
|
||||
init(params: InitParams): void;
|
||||
|
||||
/**
|
||||
* Use this function to log the user in
|
||||
*
|
||||
@@ -47,44 +50,90 @@ declare namespace facebook {
|
||||
* @param callback function to handle the response.
|
||||
* @param options optional ILoginOption to add params such as scope.
|
||||
*/
|
||||
login(callback: (response: StatusResponse) => void, options?: LoginOptions): void;
|
||||
login(callback: (response: StatusResponse) => void, options: LoginOptions): void;
|
||||
|
||||
/**
|
||||
* Use this function to log the user in
|
||||
*
|
||||
* Calling FB.login() results in the JS SDK attempting to open a popup window.
|
||||
* As such, this method should only be called after a user click event, otherwise
|
||||
* the popup window will be blocked by most browsers.
|
||||
*
|
||||
* @param options optional ILoginOption to add params such as scope.
|
||||
*/
|
||||
login(options: LoginOptions): void;
|
||||
|
||||
/**
|
||||
* The method FB.logout() logs the user out of your site and, in some cases, Facebook.
|
||||
*
|
||||
* @param callback function to handle the response
|
||||
*/
|
||||
logout(callback: (response: StatusResponse) => void): void;
|
||||
logout(callback?: (response: StatusResponse) => void): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/sharing/reference/share-dialog
|
||||
*/
|
||||
ui(params: ShareDialogParams, callback: (response: ShareDialogResponse) => void): void;
|
||||
ui(params: ShareDialogParams, callback?: (response: ShareDialogResponse) => void): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/sharing/reference/share-dialog
|
||||
*/
|
||||
ui(params: ShareOpenGraphDialogParams, callback?: (response: ShareOpenGraphDialogResponse) => void): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/pages/page-tab-dialog
|
||||
*/
|
||||
ui(params: AddPageTabDialogParams, callback?: (response: DialogResponse) => void): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/games/services/gamerequests
|
||||
*/
|
||||
ui(params: GameRequestDialogParams, callback: (response: GameRequestDialogResponse) => void): void;
|
||||
ui(params: GameRequestDialogParams, callback?: (response: GameRequestDialogResponse) => void): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/payments/reference/paydialog
|
||||
*/
|
||||
ui(params: PayDialogParams, callback: (response: PayDialogResponse) => void): void;
|
||||
ui(params: PayDialogParams, callback?: (response: PayDialogResponse) => void): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/games_payments/payments_lite
|
||||
*/
|
||||
ui(params: PaymentsLiteDialogParams, callback: (response: PaymentsLiteDialogResponse) => void): void;
|
||||
|
||||
ui(params: PaymentsLiteDialogParams, callback?: (response: PaymentsLiteDialogResponse) => void): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/videos/live-video/exploring-live
|
||||
* @see https://developers.facebook.com/docs/videos/live-video/exploring-live#golivedialog
|
||||
*/
|
||||
ui(params: LiveDialogParams, callback: (response: LiveDialogResponse) => void): void;
|
||||
ui(params: LiveDialogParams, callback?: (response: LiveDialogResponse) => void): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/sharing/reference/send-dialog
|
||||
* @see https://developers.facebook.com/docs/pages/page-tab-dialog
|
||||
*/
|
||||
ui(params: SendDialogParams | AddPageTabDialogParams, callback: (response: null) => void): void;
|
||||
ui(params: SendDialogParams, callback?: (response: DialogResponse) => void): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/marketing-api/guides/offer-ads/#create-offer-dialog
|
||||
*/
|
||||
ui(params: CreateOfferDialogParams, callback?: (response: CreateOfferDialogResponse) => void): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/marketing-api/guides/lead-ads/create#create-leadgen-dialog
|
||||
*/
|
||||
ui(params: LeadgenDialogParams, callback?: (response: LeadgenDialogResponse) => void): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/marketing-api/guides/canvas-ads#canvas-ads-dialog
|
||||
*/
|
||||
ui(params: InstantExperiencesAdsDialogParams, callback?: (response: InstantExperiencesAdsDialogResponse) => void): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/marketing-api/guides/canvas-ads#canvas-preview-dialog
|
||||
*/
|
||||
ui(params: InstantExperiencesPreviewDialogParams, callback?: (response: DialogResponse) => void): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/marketing-api/guides/collection#collection-ads-dialog
|
||||
*/
|
||||
ui(params: CollectionAdsDialogParams, callback?: (response: CollectionAdsDialogResponse) => void): void;
|
||||
|
||||
XFBML: any;
|
||||
}
|
||||
@@ -97,10 +146,11 @@ declare namespace facebook {
|
||||
xfbml?: boolean;
|
||||
frictionlessRequests?: boolean;
|
||||
hideFlashCallback?: boolean;
|
||||
autoLogAppEvents?: boolean;
|
||||
}
|
||||
|
||||
interface LoginOptions {
|
||||
auth_type?: string;
|
||||
auth_type?: 'rerequest';
|
||||
scope?: string;
|
||||
return_scopes?: boolean;
|
||||
enable_profile_selector?: boolean;
|
||||
@@ -122,12 +172,21 @@ declare namespace facebook {
|
||||
interface ShareDialogParams extends DialogParams {
|
||||
method: 'share';
|
||||
href: string;
|
||||
picture?: string;
|
||||
hashtag?: string;
|
||||
quote?: string;
|
||||
mobile_iframe?: boolean;
|
||||
}
|
||||
|
||||
interface ShareOpenGraphDialogParams extends DialogParams {
|
||||
method: 'share_open_graph';
|
||||
action_type: string;
|
||||
action_properties: { [property: string]: any };
|
||||
href: string;
|
||||
hashtag?: string;
|
||||
quote?: string;
|
||||
mobile_iframe?: false;
|
||||
}
|
||||
|
||||
interface AddPageTabDialogParams extends DialogParams {
|
||||
method: 'pagetab';
|
||||
redirect_uri: string;
|
||||
@@ -137,13 +196,13 @@ declare namespace facebook {
|
||||
method: 'apprequests';
|
||||
message: string;
|
||||
action_type?: 'send' | 'askfor' | 'turn';
|
||||
data?: number;
|
||||
data?: string;
|
||||
exclude_ids?: string[];
|
||||
filters?: 'app_users' | 'app_non_users' | Array<{ name: string, user_ids: string[] }>;
|
||||
max_recipients?: number;
|
||||
object_id?: string;
|
||||
suggestions?: string[];
|
||||
title?: number;
|
||||
title?: string;
|
||||
to?: string | number;
|
||||
}
|
||||
|
||||
@@ -160,10 +219,11 @@ declare namespace facebook {
|
||||
quantity?: number;
|
||||
quantity_min?: number;
|
||||
quantity_max?: number;
|
||||
pricepoint_id?: string;
|
||||
request_id?: string;
|
||||
test_currency?: string;
|
||||
}
|
||||
|
||||
|
||||
interface PaymentsLiteDialogParams extends DialogParams {
|
||||
method: 'pay';
|
||||
action: 'purchaseiap';
|
||||
@@ -179,6 +239,43 @@ declare namespace facebook {
|
||||
broadcast_data?: LiveDialogResponse;
|
||||
}
|
||||
|
||||
interface CreateOfferDialogParams extends DialogParams {
|
||||
account_id: string;
|
||||
display: 'popup';
|
||||
method: 'create_offer';
|
||||
objective: 'APP_INSTALLS' | 'CONVERSIONS' | 'LINK_CLICKS' | 'OFFER_CLAIMS' | 'PRODUCT_CATALOG_SALES' | 'STORE_VISITS';
|
||||
page_id: string;
|
||||
}
|
||||
|
||||
interface LeadgenDialogParams extends DialogParams {
|
||||
account_id: string;
|
||||
display: 'popup';
|
||||
method: 'lead_gen';
|
||||
page_id: string;
|
||||
}
|
||||
|
||||
interface InstantExperiencesAdsDialogParams extends DialogParams {
|
||||
display: 'popup';
|
||||
method: 'canvas_editor';
|
||||
business_id: string;
|
||||
page_id: string;
|
||||
canvas_id?: string;
|
||||
}
|
||||
|
||||
interface InstantExperiencesPreviewDialogParams extends DialogParams {
|
||||
display: 'popup';
|
||||
method: 'canvas_preview';
|
||||
canvas_id: string;
|
||||
}
|
||||
|
||||
interface CollectionAdsDialogParams extends InstantExperiencesAdsDialogParams {
|
||||
account_id: string;
|
||||
canvas_id?: undefined;
|
||||
template_id: string;
|
||||
product_catalog_id?: string;
|
||||
product_set_id?: string;
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
//
|
||||
// RESPONSES
|
||||
@@ -190,48 +287,73 @@ declare namespace facebook {
|
||||
signedRequest: string;
|
||||
userID: string;
|
||||
grantedScopes?: string;
|
||||
reauthorize_required_in?: number;
|
||||
}
|
||||
|
||||
|
||||
interface StatusResponse {
|
||||
status: string;
|
||||
status: 'authorization_expired' | 'connected' | 'not_authorized' | 'unknown';
|
||||
authResponse: AuthResponse;
|
||||
}
|
||||
|
||||
interface ShareDialogResponse {
|
||||
post_id?: string;
|
||||
interface DialogResponse {
|
||||
error_code?: number;
|
||||
error_message?: string;
|
||||
}
|
||||
|
||||
interface GameRequestDialogResponse {
|
||||
interface ShareDialogResponse extends DialogResponse {
|
||||
post_id: string;
|
||||
}
|
||||
|
||||
interface ShareOpenGraphDialogResponse extends DialogResponse {
|
||||
post_id: string;
|
||||
}
|
||||
|
||||
interface GameRequestDialogResponse extends DialogResponse {
|
||||
request: string;
|
||||
to: string[];
|
||||
}
|
||||
|
||||
interface PayDialogResponse {
|
||||
interface PayDialogResponse extends DialogResponse {
|
||||
payment_id: string;
|
||||
amount: string;
|
||||
currency: string;
|
||||
quantity: string;
|
||||
request_id: string;
|
||||
status: string;
|
||||
request_id?: string;
|
||||
status: 'completed' | 'initiated';
|
||||
signed_request: string;
|
||||
}
|
||||
|
||||
interface PaymentsLiteDialogResponse {
|
||||
interface PaymentsLiteDialogResponse extends DialogResponse {
|
||||
app_id: number;
|
||||
developer_payload?: string;
|
||||
payment_id: number;
|
||||
product_id?: string;
|
||||
purchase_time?: number;
|
||||
purchase_token?: string;
|
||||
signed_request?: string;
|
||||
error_code?: number;
|
||||
error_message?: string;
|
||||
product_id: string;
|
||||
purchase_time: number;
|
||||
purchase_token: string;
|
||||
signed_request: string;
|
||||
}
|
||||
|
||||
interface LiveDialogResponse {
|
||||
|
||||
interface LiveDialogResponse extends DialogResponse {
|
||||
id: string;
|
||||
stream_url: string;
|
||||
secure_stream_url: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
interface CreateOfferDialogResponse extends DialogResponse {
|
||||
id: string;
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
interface LeadgenDialogResponse extends DialogResponse {
|
||||
formID: string;
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
interface InstantExperiencesAdsDialogResponse extends DialogResponse {
|
||||
id: string;
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
interface CollectionAdsDialogResponse extends InstantExperiencesAdsDialogResponse {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user