A facebook API for the Node.JS backend in TypeScript.
npm install facebook-ts --save
// TypeScript
import * as FB from 'facebook-ts'
// JavaScript
var FB = require('facebook-ts')
FB.settings.setSecret('secret-provided-by-facebook');
FB.settings.setClientId('client-id-provided-by-facebook');
FB.getUser('someFacebookId')
.then(user => { /* ... */ });
function setSecret(secret: string) => void;
Set the secret as provided by Facebook
function getSecret() => string;
Returns the secret that you provided
function setClientId(secret: string|number) => void;
Set the client id as provided by Facebook
function getClientId() => string;
Returns the client id that you provided
function setApiVersion(version: string) => void;
...
function getApiVersion() => string;
function accessToken(usedStoredToken = true) => Promise<string>;
Get an access token from Facebook for accessing the rest of the API.
Use the stored token is one is present.
function verifyToken(userStatus: Status) => Promise<TokenStatus>;
See: Status and TokenStatus
Returns the status of a user's session/token.
userStatus
is an object provided by the Facebook SDK function getLoginStatus()
.
function getUser(facebookId: string|number) => Promise<User>;
See User
interface Status {
status: string;
authResponse: {
accessToken: string;
expiresIn: string;
signedRequest: string;
userID: string;
}
}
interface TokenStatus {
data?: {
app_id: string;
application: string;
expires_at: number;
is_valid: boolean;
scopes: Array<string>;
user_id: string;
error?: {
code: number;
message: string;
subcode: number;
}
},
error?: {
message: string,
type: string,
is_transient: boolean,
code: number
}
}
interface User {
name: string;
id: string;
}