2.1.0 • Published 3 years ago
@p803/facebook-sdk v2.1.0
Facebook SDK for JavaScript
This repository contains a JavaScript package that allows you to access the Facebook SDK for JavaScript from your JavaScript project.
Installation
This package can be installed with npm. Run this command:
npm install @p803/facebook-sdk
or use the standalone format:
<script src="https://unpkg.com/@p803/facebook-sdk"></script>
Usage
Let's see how the official login example will look like when using this SDK.
// Import the package.
import facebookSdk from '@p803/facebook-sdk' // node
// const facebookSdk = window.p803.facebookSdk // browser
// Set sdk parameters.
facebookSdk.params = {
appId: '{app-id}', // required
version: 'v6.0', // required
xfbml: true, // optional
// other params...
}
// Grab the sdk.
const sdk = await facebookSdk()
// Login the user.
const response = await sdk.login({
scope: ['email', 'user_likes'],
return_scopes: true,
});
// Print details.
if (response.authResponse) {
const me = await sdk.api('/me');
console.log(`Good to see you, ${me.name}.`);
} else {
console.log('User cancelled login or did not fully authorize.');
}
// ...
// Subsequent calls will return the same sdk instance.
const sdk = await facebookSdk(); // it's singleton