• Stars
    star
    188
  • Rank 205,563 (Top 5 %)
  • Language
    JavaScript
  • License
    Other
  • Created about 14 years ago
  • Updated almost 13 years ago

Reviews

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

Repository Details

A javascript (nodejs) implementation of facebook's client for oauth and rest+graph api

node-facebook-client README

Version: 1.6.1

Official Site: http://dracoblue.net/

node-facebook-client is copyright 2010-2012 by DracoBlue http://dracoblue.net

What is node-facebook-client?

The node-facebook-client library is a set of nodejs classes to communicate with the rest and graph api provided by facebook.

It works great if you embed the facebook connect button on your page and want to use the rest + graph api by facebook. Oauth-support may work but is not tested that well.

The library is not officially created nor maintained by facebook. It is created by dracoblue and licensed under the terms of MIT License.

Example

This small example uses the FacebookClient class to retrieve the name of a user. requst.headers are the headers from the server request.

var FacebookClient = require("facebook-client").FacebookClient;

var facebook_client = new FacebookClient(
    "yourappid", // configure like your fb app page states
    "yourappsecret", // configure like your fb app page states
    {
        "timeout": 10000 // modify the global timeout for facebook calls (Default: 10000)
    }
);

facebook_client.getSessionByRequestHeaders(request.headers)(function(facebook_session) {
    facebook_session.graphCall("/me", {
    })(function(result) {
        console.log('Username is:' + result.name);
    });
    facebook_session.graphCall("/me/feed", {message:"I love node.js!"}, 'POST')(function(result) {
        console.log('The new feed post id is: ' + result.id);
    });
});

A full example may be executed with: node run_example.js. Please configure yourappid+yourappsecret in that file first.

Graph API

FacebookClient#graphCall(path, params[, method, options])

Doing a call against the graph server.

client.graphCall(path, params, method)(function(result) {
    // 
});

The parameter method can be omitted and is 'GET' in this case. You may use options.timeout = 5000 to modify the timeout until the request will be canceled.

Rest API

FacebookSession#restCall(method, params, access_token[, options])

Doing a signed call against the rest api server, by using the session of the user.

session.restCall("users.getInfo", {
    fields: "name",
    uids: session.uid
})(function(response_users) {
    // work with it
});

You may use options.timeout = 5000 to modify the timeout until the request will be canceled.

General API

FacebookClient#getSessionByRequestHeaders(request_headers)

Use the request headers to retrieve the session.

facebook_client.getSessionByRequestHeaders(request.headers)(function(facebook_session) {
    // session is either undefined or a valid FacebookSession
});

FacebookSession#isValid()

Calls /me on the graph api, to check whether the session is still valid or the user has already logged out.

session.isValid()(function(is_valid) {
    // is either true or false
});

Remember to do that only when necessary and not on every request.

FacebookClient#getSessionByAccessToken(access_token)

Creating a new FacebookSession instance with a given access_token.

FacebookSession#getId()

Retrieving the id of the session.

session.getId()(function(id) {
    // is either a string or undefined, in case the session has no id
});

FacebookSession#getMeta()

Tries to retrieve all data from the graph call /me for the user.

session.getMeta()(function(user_data) {
    // work with it
});

Internal API

FacebookClient#getAccessToken(access_params)

Retrieving an AccessToken with the given parameters. You don't need to use this function if you used FacebookClient#getSessionByRequestHeaders.

client.getAccessToken(access_params)(function(access_token, expires) {
    // 
});

FacebookSession#retrieveAccessToken(code, redirect_uri)

Retrieve an access token by providing a code and a redirect_uri. Usually from successful oauth redirect.

FacebookSession#injectAccessToken(access_token)

Used to inject an access_token into an existing FacebookSession. This will enable calls like FacebookSession#restCall and FacebookSession#graphCall to work authenticated. It is triggered by FacebookClient#getSessionByRequestHeaders after successful creation of the session.

FacebookSession#getAccessToken(access_params)

Retrieving an AccessToken with the given parameters and injecting it into the FacebookSession.

FacebookToolkit.generateSignature(params, api_secret)

Calculates the signature for a given set of parameters and the api_secret.

Changelog

  • 1.6.1 (2012/10/02)
    • removed unused sys
  • 1.6.0 (2012/01/22)
    • rewrote requests from multiple parameters to options-object
    • added options.timeout for restCall and graphCall #22
    • fixed error handling in case the timeout is reached #22
  • 1.5.3 (2012/01/22)
    • fixed issue with graphCall and method parameter #21
  • 1.5.2 (2012/01/07)
    • added multiquery-support for graphCall #12
  • 1.5.1 (2012/01/06)
    • fixed isValid: throwed an exception, when user_data.error was not existant
    • added backward compatibility for node 0.4.x, if toString('hex') was missing
  • 1.5.0 (2012/01/05)
    • added support for fbsr-cookie from new facebook auth #16
    • added support for lazy-access-token retrieval if oauth-code is given
    • added timeout of 10 seconds for each call against facebook #15
  • 1.4.0 (2011/10/06)
    • added multiquery-support. #12
  • 1.3.0 (2011/04/26)
    • added FacebookSession#isValid
    • fixed expires validation fixes #5
    • added method argument to session.graphCall to permit POSTing in addition to GETting
  • 1.2.0 (2011/03/09)
    • added support for node 0.4
  • 1.1.0 (2010/12/29)
    • removed session_key support
    • added example
  • 1.0.1 (2010/12/29)
    • added secure url for access_token
  • 1.0.0 (2010/10/05)
    • Initial release

Contributors

License

node-facebook-client is licensed under the terms of MIT. See LICENSE for more information.

More Repositories

1

spludo

Spludo is high performance, evented, server side, prototype based, javascript mvc web framework. It includes DI+AOP and a Convention-Over-Configuration Approach.
JavaScript
75
star
2

jsb

A very extendable Toolkit to inject Javascript Behaviour into rendered HTML without Inline Javascript. (jsb was formerly known as JsBehaviourToolkit)
JavaScript
52
star
3

Craur

A lossless xml to json and json to xml converter (and csv/xlsx/yaml). Writing PHP Json/Xml/Csv/Yaml/excel Importers made easy.
PHP
46
star
4

activitystreams-php

A activitystreams server and client in php.
PHP
27
star
5

markdown-papers

Use a specific markdown file to write proper formatted papers and articles.
JavaScript
21
star
6

lua-oauth

OAuth Implementation for Lua
Lua
19
star
7

twtxt-registry

A small registry server for twtxt, which allows to query for mentions and hash tags.
JavaScript
17
star
8

PhpDebugToolbar

A debugging toolbar for agavi.
PHP
15
star
9

hateoas-client-js

This project is still alpha. The intention is to create an async RESTful Client for the Browser, which supports (unlike so called rest clients) also following links and navigate through a REST api.
JavaScript
13
star
10

lua-native-ssi-nginx

Reimplement and enhance ssi logic in nginx with lua module
Lua
11
star
11

state-of-docker-on-m1

Shell
11
star
12

gitlab-jira-webhook

This little webhook pushes gitlab events directly to jira as remote links.
JavaScript
9
star
13

travis-ci-nginx-php-fpm-test

Testing travis ci with php fpm and nginx
9
star
14

spludo-plugins

Official plugins for the spludo framework.
JavaScript
9
star
15

hateoas-browser

A generic web based browser for hateoas apis
JavaScript
8
star
16

goss-metrics-exporter

JavaScript
7
star
17

pp-nginx

A slim but very powerful nginx module for puppet
Puppet
6
star
18

infoviz

JavaScript
5
star
19

logging-js

Easy lib to trace function calls and write log messages into the `console` object. Requires require.js.
JavaScript
4
star
20

docsforit

This is a sample application built with spludo.
JavaScript
4
star
21

enhanced-node-api

An enhanced api browser for node.JS
JavaScript
4
star
22

swarmbot

A bot for http://swarmfight.com/ (you'll need a api key to use that bot).
JavaScript
4
star
23

iasur

A very thin web and api based file upload and distribution service.
HTML
4
star
24

http-response-headers

This small java library is used with spring to use Annotations for HTTP Response Headers.
Java
4
star
25

branchy

A tool to manage feature branches with svn (like gitflow)
PHP
4
star
26

mdslides

Source for http://mdslides.erstmal.com
JavaScript
3
star
27

sudoku-android

JavaScript
3
star
28

cattle_ui

The library cattle_ui is a set of mootools classes to use the awesome jQueryUI-CSS without jQuery but by using MooTools.
JavaScript
3
star
29

naith

A simple php test runner, without the bloat of phpunit
PHP
3
star
30

node-duplicity

JavaScript
3
star
31

traffic-trouble

3
star
32

keycombo.js

A library to fetch key combinations in javascript (currently requires mootools)
JavaScript
3
star
33

spludo-facebook-session

A FacebookSessionManager for Spludo, so you can use Facebook-Connect as session handler.
JavaScript
3
star
34

graphql-hateoas-bridge-nginx

This is an effort to add a generic graphql endpoint before a hateoas compliant api (like hal, json-hc) with nginx's lua module.
Lua
2
star
35

YtMooPlayer

A javascript interface/class for the Youtube Chromeless Player built for Mootools.
JavaScript
2
star
36

Tambo

A german agavi tutorial, I wrote back in 2009. Hope it's useful for somebody!
2
star
37

jolokia-metrics-exporter

A service to export jolokia metrics to prometheus. Docker Image at https://hub.docker.com/r/dracoblue/jolokia-metrics-exporter
JavaScript
2
star
38

toolsapi-shell

Shell
1
star
39

xunit-metrics-exporter

JavaScript
1
star
40

DModule

DModule is a development and testingframwork for the programming language pawn and delivers also core modules for scripting the gta san andreas multiplayer modification sa-mp.
Lua
1
star
41

symfony-composer-docker-performance-test

This is a reference repository for the performance blogpost at https://dracoblue.net/dev/performance-boost-for-symfony-composer-projects-in-docker/
PHP
1
star
42

static-response-exporter

Sometimes all you want to do is exporting a specific environment variable dependent on set of text responses.
Dockerfile
1
star
43

gitlab-artifacts-browser

JavaScript
1
star
44

transcoding.sh

Shell
1
star