facebook-ts
v0.2.3
Published
Facebook API for Node
Downloads
4
Readme
facebook-ts
A facebook API for the Node.JS backend in TypeScript.
Installation
npm install facebook-ts --save
Usage
// 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 => { /* ... */ });
API
Settings
setSecret
function setSecret(secret: string) => void;
Set the secret as provided by Facebook
getSecret
function getSecret() => string;
Returns the secret that you provided
setClientId
function setClientId(secret: string|number) => void;
Set the client id as provided by Facebook
getClientId
function getClientId() => string;
Returns the client id that you provided
setApiVersion
function setApiVersion(version: string) => void;
...
getApiVersion
function getApiVersion() => string;
accessToken
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.
verifyToken
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()
.
getUser
function getUser(facebookId: string|number) => Promise<User>;
See User
Interfaces
Status
interface Status {
status: string;
authResponse: {
accessToken: string;
expiresIn: string;
signedRequest: string;
userID: string;
}
}
TokenStatus
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
}
}
User
interface User {
name: string;
id: string;
}