• Stars
    star
    505
  • Rank 87,373 (Top 2 %)
  • Language
    CSS
  • License
    MIT License
  • Created over 10 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Micro-library that lets you integrate browser and Cordova apps with Facebook with no plugin or SDK dependency.

OpenFB

OpenFB is a Micro-Library for Facebook integration in JavaScript apps running in the browser and in Cordova.

OpenFB has no dependency: You don't need the Facebook plugin when running in Cordova. You also don't need the Facebook SDK.

OpenFB allows you to login to Facebook and execute any Facebook Graph API request.

Here are a few code examples...

Login using Facebook:

openFB.login(callback, {scope: 'email,read_stream,publish_actions'});

Get the user's list of friends:

openFB.api({path: '/me/friends', success: successHandler, error: errorHandler});

Post on the user's feed:

openFB.api(
    {
        method: 'POST',
        path: '/me/feed',
        params: {
            message: 'Testing the Facebook Graph API'
        },
        success: successHandler,
        error: errorHandler
    });

The approach used in OpenFB (plain OAuth + direct requests to Graph API endpoints) is simple and lightweight, but it is definitely not perfect.

Pros:

  • No plugin dependency and no uncertainties when new versions of Cordova or the Facebook SDK are released.
  • Works for all platforms, including platforms for which a version of the Facebook plugin doesn't exist.
  • Works for both browser-based apps and Cordova apps.

Cons:

  • Not full-fledged, less out-of-the box features.
  • Integration not as tight. For example, no native dialogs, etc.

Browser and Cordova Apps

The library works for both browser-based apps and Cordova/PhoneGap apps. When running in a browser, the OAuth URL redirection workflow happens in a popup window. When running in Cordova, it happens inside an "In-App Browser".

Getting Started

Creating a Facebook application

  1. Login to Facebook

  2. Access https://developers.facebook.com/apps, and click Add New App

  3. Select www as the platform

  4. Type a unique name for your app and click Create New Facebook App ID

  5. Specify a Category, and click Create App ID

  6. Click My Apps in the menu and select the app you just created

  7. Click Settings in the left navigation

  8. Click the Advanced Tab

  9. In the OAuth Settings section, add the following URLs in the Valid OAuth redirect URIs field:

  10. Click Save Changes

Running the Sample in the Browser

  1. Copy the Facebook App ID for the app you just created and paste it as the first argument of the openFB.init() method invocation in index.html.
  2. Load index.html, from a location that matches the redirect URI you defined above. For example: http://localhost:8100

Running the Sample in Cordova

  1. Create a Cordova project

    cordova create sample com.openfb.sample sample
    
  2. Add the InAppBrowser Plugin

    cd sample
    cordova plugins add org.apache.cordova.inappbrowser
    
  3. Delete the contents of the www directory

  4. Copy index.html and openfb.js from the OpenFB project to the www directory of your Cordova project

    Make sure your index.html includes <script src="cordova.js"></script>. cordova.js does not need to (and shouldn't be) present in your www folder: it is automatically injected by the cordova build process.

  5. Make sure you are in your Cordova project's root directory, add a platform, and build the project. For example:

    cordova platform add ios
    cordova build ios
    
  6. Run the project on device or in the emulator

AngularJS Wrapper

If you are using AngularJS, you can use ngOpenFB which provides a wrapper around the OpenFB library and allows you to use OpenFB "the Angular way":

  • As an Angular service instead of a global object
  • Using promises instead of callbacks

indexng.html provides an AngularJS sample.

Check out the Ionic Tutorial for a complete example.

Summary

The Facebook Plugin is still the best technical solution to integrate your Cordova app with Facebook because it provides a tighter integration (using native dialogs, etc). However, if you are looking for a lightweight and easy-to-set-up solution with no dependencies, or if you are targeting mobile platforms for which an implementation of the plugin is not available, you may find this library useful as well.

More Repositories

1

backbone-directory

Sample Application built with Backbone.js and 3 different UI toolkits: Twitter Bootstrap, jQuery Mobile, and custom iPhone skins
PHP
1,524
star
2

nodecellar

Sample application built with Backbone.js, Twitter Bootstrap, Node.js, Express, MongoDB
JavaScript
1,203
star
3

backbone-cellar

A Backbone.js tutorial
JavaScript
911
star
4

PageSlider

A simple library providing hardware accelerated page transitions for Mobile Apps
JavaScript
498
star
5

directory-backbone-bootstrap

Employee Directory sample application built with Backbone.js and Twitter Bootstrap
JavaScript
465
star
6

sociogram-angular-ionic

A sample application demonstrating how to integrate with Facebook in your Angular/Ionic apps
JavaScript
367
star
7

cordova-tutorial

Cordova Tutorial
JavaScript
323
star
8

es6-tutorial

ECMAScript 6 Tutorial
CSS
300
star
9

angular-directory

A sample mobile application built with AngularJS
CSS
297
star
10

directory-angular-ionic

Sample Employee Directory application built with Ionic and AngularJS
JavaScript
272
star
11

angular-cellar

Sample Angular.js application (Wine Cellar Management App)
PHP
270
star
12

ionic2-realty

Sample Application with Ionic 2 and Angular 2
JavaScript
257
star
13

backbone-jquerymobile

Sample App showing how to use Backbone.js and jQuery Mobile together
JavaScript
220
star
14

ionic-tutorial

Ionic Tutorial
JavaScript
219
star
15

react-trader

Sample application built with React and Socket.io
JavaScript
215
star
16

offline-sync

Simple Offline Data Synchronization for Mobile Web and PhoneGap Applications
PHP
207
star
17

directory-ionic-nodejs

Sample Employee Directory App built with Ionic and Node.js
JavaScript
206
star
18

belgian-beer-explorer

App built with React, Bootstrap, Node.js, Postgres
JavaScript
203
star
19

pageslider-react

Micro library for animated page transitions using React
CSS
202
star
20

wine-cellar-php

PHP
183
star
21

forcejs

Micro library to use the Salesforce REST APIs in JavaScript Apps
JavaScript
176
star
22

react-employee-directory

Sample Application with the React Framework
Objective-C
175
star
23

sociogram

A sample application exploring the Facebook SDK and the Graph API
JavaScript
174
star
24

directory-react-nodejs

Sample application with React and Node.js
CSS
169
star
25

mobile-ui-patterns

JavaScript
168
star
26

directory-backbone-topcoat

Sample Mobile / PhoneGap Application built with Backbone.js and TopCoat
JavaScript
164
star
27

react-university

Sample application with React and the Lightning Design System
JavaScript
158
star
28

lightning-react-app

JavaScript
150
star
29

directory-rest-nodejs

Node.js / MongoDB RESTFul services for the Employee Directory sample application
JavaScript
140
star
30

backbone-jax-cellar

Java
136
star
31

phonegap-explorer

PhoneGap API reference app. Provides Complete PhoneGap API reference documentation and allows you to experiment with the APIs inside the application.
JavaScript
128
star
32

directory-backbone-ratchet

Sample Mobile / PhoneGap App built with Backbone.js and Ratchet
CSS
124
star
33

directory-backbone-topcoat-require

121
star
34

cors-proxy

Simple Node.js-based CORS Proxy
JavaScript
116
star
35

sociogram-mobile

Starter-Kit Application for PhoneGap/Facebook integration
JavaScript
109
star
36

ioconf

Conference sample app built with AngularJS and Ionic
JavaScript
104
star
37

salesforce-developer-workshop

Step-by-step tutorial for developers new to the Salesforce platform
CSS
99
star
38

directory-backbone-bootstrap-require

JavaScript
91
star
39

pull-to-refresh

Example of Using Pull-To-Refresh in PhoneGap / Cordova apps
CSS
86
star
40

PictureFeed

85
star
41

directory-backbone-browserify

Browserify sample applicarion, using Backbone and Handlebar templates
JavaScript
83
star
42

olympic-dashboard-d3

CSS
81
star
43

react-trivia

Trivia app built with React
JavaScript
79
star
44

ionic2-realty-rest

Sample application with Ionic 2, Angular 2, and REST services powered by Node.js
JavaScript
76
star
45

directory-rest-php

PHP-based RESTFul services for the employee directory sample app
PHP
70
star
46

belgian-beer-explorer-ionic

Belgian Beer Explorer App built with Ionic Framework
JavaScript
68
star
47

wine-cellar-java

Java
65
star
48

salesforce-conference-demo

CSS
62
star
49

phonegap-workshop

Lab materials for PhoneGap workshop
JavaScript
57
star
50

forceng

Micro-Library to use Salesforce REST API in AngularJS apps
JavaScript
52
star
51

ionic2-employee-directory

Sample app with Ionic 2
JavaScript
51
star
52

employee-directory-app

Employee Directory App for iPhone
JavaScript
50
star
53

force-server

Development server for Force.com
JavaScript
48
star
54

employee-directory-react-native

Sample Employee Directory App built with React Native
JavaScript
48
star
55

phonegap-day-eu

47
star
56

phonegap-dropbox-sync

PhoneGap Plugin for the Dropbox Sync API
JavaScript
45
star
57

lightning-container-component-samples

CSS
43
star
58

salesforce-bot-messenger

Sample Salesforce bot for Facebook Messenger
JavaScript
38
star
59

phonegap-s3-upload

upload
36
star
60

lightning-trader

Sample trader desktop app built with React and the Lightning Design System
HTML
36
star
61

olympic-dashboard-chartjs

CSS
33
star
62

keypoint-phonegap-performance

JavaScript
31
star
63

lightning-react

Project demonstrating how to build Salesforce Lightning Components with React
JavaScript
31
star
64

MobileDashboard

A sample dashboard application fro mobile devices
ActionScript
30
star
65

salesforce-bot-toolkit

A bot toolkit for Salesforce
Apex
30
star
66

slackforce

Sample Message Broker to enable Slack to Salesforce communication using Slash Commands
JavaScript
30
star
67

employee-directory-ios

A native implementation of the Employee Directory application for iOS
Objective-C
29
star
68

lightning-component-apex-continuation

Sample app showing how to invoke an Apex Continuation from a Lightning Component
JavaScript
27
star
69

es6-tutorial-react

JavaScript
26
star
70

keypoint-phonegap-backbone

JavaScript
25
star
71

force-contacts-angular-ionic

A sample contact manager application using Ionic, AngularJS, and Force.com.
JavaScript
25
star
72

MobileTrader

ActionScript
25
star
73

es6-tutorial-data

JavaScript
24
star
74

salesforce-canvas-demo

JavaScript
23
star
75

SalesbuilderMobile

ActionScript
23
star
76

phonegap-workshop-solutions

Step-by-step solutions for the phonegap-workshop
JavaScript
21
star
77

phonegap-workshop-jquk2014

JavaScript
21
star
78

lightning-code-sharing

Code Sharing Strategies in Lightning Components
JavaScript
21
star
79

salesforce-contacts-react

Sample Salesforce Application built with React
JavaScript
17
star
80

belgian-beer-explorer-lightning

CSS
17
star
81

es6-tutorial-solutions

Unit-by-unit solutions for the ES6 tutorial
JavaScript
17
star
82

angular2-salesforce

Sample application with Angular2 and Salesforce
TypeScript
17
star
83

lc-vf-communication

Example of bidirectional communication between Lightning Components and Visualforce pages
JavaScript
16
star
84

ionic2-salesforce-sample

Sample Application: Ionic 2 with a Salesforce back-end
JavaScript
15
star
85

lwc-pwa-demo

PWA sample app created with Lightning Web Components and Workbox
JavaScript
15
star
86

soql-explorer

Force.com mini API explorer
JavaScript
14
star
87

salesforce-developer-advanced

CSS
14
star
88

EmployeeDirectory

JavaScript
14
star
89

brackets-dropbox

JavaScript
13
star
90

ionic2-realty-salesforce

JavaScript
13
star
91

salesforce-bot-slack

A simple Salesforce bot for Slack
JavaScript
13
star
92

flex-spring-mobile-testdrive

Java
12
star
93

ionic-slides

JavaScript
11
star
94

react-mortgage-calc

Sample app written with React and built with Babel
JavaScript
10
star
95

javascript-data-adapters

Simple data adapters
JavaScript
9
star
96

employee-directory-services

Sample REST services for Employee Directory application
JavaScript
9
star
97

northern-trail-manufacturing

Sample application demonstrating Salesforce / Node.js integration using platform events
JavaScript
8
star
98

force-contacts-ratchet

A sample Salesforce.com Mobile App with Ratchet 2.0
JavaScript
8
star
99

intro-to-es6

JavaScript
8
star
100

training

PHP
8
star