npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fb-sdk-wrapper

v1.1.0

Published

Wraps around the Facebook Javascript SDK to make it usable as a ES6 module

Downloads

2,060

Readme

fb-sdk-wrapper

Wraps around the Facebook Javascript SDK to make it usable as a ES6 module. Instead of having to add a script tag to your html like it's still 2010, just import this module and it will do it for you. As a bonus it will provide you with a nicer api by using promises.

Essentially, this library exposes functions with almost the same signature as the official JS SDK. The only difference is that instead of requiring callback functions as parameters of the SDK functions, the wrapper will return a promise for the response value.

fb-sdk-wrapper focuses on the 'core' authentication, graph API and UI methods and makes them a little nicer to use. The other functionality can by accessed by simply referring to window.FB (after the load function has resolved).

Installing

Use the package manager of your choosing:

# npm
npm install fb-sdk-wrapper

# yarn
yarn add fb-sdk-wrapper

Usage

Here are some examples of how to use FB SDK Wrapper.

Again, the main thing to keep in mind is that this API tries to follow the official FB JS SDK reference as closely as possible except that all callbacks are replaced by promises for the response.

Loading and initializing the SDK

The first steps to get the SDK to work:

import * as Facebook from 'fb-sdk-wrapper';

Facebook.load()
  .then(() => {
    Facebook.init({
      appId: config.appId
    });
  });

Authentication and app authorisation

Next step is to log in and get the user to authorise your app.

import * as Facebook from 'fb-sdk-wrapper';

// Get current state
Facebook.getLoginStatus()
  .then(response) => {
    if (response.status === 'connected') {
      // logged in
    } else {
      // not logged in
    }
  });

// Login + get basic authorisation ('public profile')
Facebook.login()
  .then((response) => {
    if (response.status === 'connected') {
      // logged in
    } else {
      // not logged in
    }
  });

// Login + get authorisation for additional scopes
Facebook.login({
    scope: 'public_profile,email,user_friends',
    return_scopes: true
  })
  .then((response) => {
    if (response.status === 'connected') {
      // logged in
    } else {
      // not logged in
    }
  });

// Logout
Facebook.logout()
  .then((response) => {
    // logged out
  });

Graph API queries

When that's out of the way, you can query the graph API:

import * as Facebook from 'fb-sdk-wrapper';

// Simplest call
Facebook.api('/dewolfficial/posts')
  .then((response) => {
    // data's here!
  });

// A bit more elaborate request
Facebook.api('/168546367204_10155245614532205', 'get', {
    fields: 'created_time,id,message,message_tags'
  })
  .then((response) => {
    // data's here!
  });

Dependencies

None.

License

MIT, see LICENSE.

Author

Erik Hagreis