function Facebook(opts, _internalInherit) { (0, _classCallCheck3.default)(this, Facebook); if (_internalInherit instanceof Facebook) { this[_opts] = (0, _create2.default)(_internalInherit[_opts]); } else { this[_opts] = (0, _create2.default)(defaultOptions); } if (typeof opts === 'object') { this.options(opts); } }
...
## Library usage
Libraries can isolate themselves from the options belonging to the default `FB` by creating an instance of the `Facebook` class.
```javascript
// ES5
var FB = require('fb'),
fb = new FB.Facebook(options);
// ES2015 w/ require()
var {Facebook, FacebookApiException} = require('fb'),
fb = new Facebook(options);
// ES2015 w/ import through Babel
import {Facebook, FacebookApiException} from 'fb';
...
function FacebookApiException(res) { this.name = 'FacebookApiException'; this.message = (0, _stringify2.default)(res || {}); this.response = res; Error.captureStackTrace(this, this.constructor.name); }
n/a
api = function () { [native code] }
...
```
## Graph Api
### Get
```js
FB.api('4', function (res) {
if(!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
return;
}
console.log(res.id);
console.log(res.name);
});
...
extend = function () { [native code] }
...
## Multi-app usage
Applications that run on behalf of multiple apps with different Facebook appIds and secrets can use `.extend` (on `FB` or any `Facebook
` instance) to create a new instance which inherits options not set on it from the instance it is created from (like the API `version
` your application is coded against).
```javascript
FB.options({version: 'v2.4'});
var fooApp = FB.extend({appId: 'foo_id', appSecret: 'secret'}),
barApp = FB.extend({appId: 'bar_id', appSecret: 'secret'});
```
## Graph Api
### Get
...
getAccessToken = function () { [native code] }
...
```
### getAccessToken
*Unlike `setAccessToken` this is a standard api and exists in FB JS SDK.*
```js
FB.setAccessToken('access_token');
var accessToken = FB.getAccessToken();
```
### AppSecret Proof
For improved security, as soon as you provide an app secret and an access token, the
library automatically computes and adds the appsecret_proof parameter to your requests.
## Configuration options
...
getLoginUrl = function () { [native code] }
...
### getLoginUrl
*This is a non-standard api and does not exist in the official client side FB JS SDK.*
This returns the redirect url for a [manual login flow](https://developers.facebook.com/docs/facebook-login/manually-build-a-login
-flow).
```js
FB.getLoginUrl({
scope: 'email,user_likes',
redirect_uri: 'http://example.com/'
});
```
These options are accepted and all correspond to url parameters documented in Facebook's manual login flow documentation.
...
napi = function () { [native code] }
...
## Node style callback with FB.napi
*This is a non-standard api and does not exist in the official client side FB JS SDK.*
`FB.napi` takes the same input as `FB.api`. Only the callback parameters is different. In the original `FB.api`, the callback expects
one parameter which is the response. In `FB.napi` the callback expects two parameters instead of one and follows the node standards
. The first parameter is an error which is always of type `FacebookApiException` and the second parameter is the same response as
in `FB.api`. Error response can be accessed using `error.response` which is the same response as the response when using `FB.api
`.
```js
FB.napi('4', function(error, response) {
if(error) {
if(error.response.error.code === 'ETIMEDOUT') {
console.log('request timeout');
}
else {
console.log('error', error.message);
}
...
options = function () { [native code] }
...
```
## Multi-app usage
Applications that run on behalf of multiple apps with different Facebook appIds and secrets can use `.extend` (on `FB` or any `Facebook
` instance) to create a new instance which inherits options not set on it from the instance it is created from (like the API `version
` your application is coded against).
```javascript
FB.options({version: 'v2.4'});
var fooApp = FB.extend({appId: 'foo_id', appSecret: 'secret'}),
barApp = FB.extend({appId: 'bar_id', appSecret: 'secret'});
```
## Graph Api
### Get
...
parseSignedRequest = function () { [native code] }
...
*This is a non-standard api and does not exist in the official client side FB JS SDK.*
```js
var signedRequestValue = 'signed_request_value';
var appSecret = 'app_secret';
var signedRequest = FB.parseSignedRequest(signedRequestValue, appSecret);
if(signedRequest) {
var accessToken = signedRequest.oauth_token;
var userId = signedRequest.user_id;
var userCountry = signedRequest.user.country;
}
```
...
setAccessToken = function () { [native code] }
...
console.log(res.name);
});
```
### Post
```js
FB.setAccessToken('access_token');
var body = 'My first post using facebook-node-sdk';
FB.api('me/feed', 'post', { message: body }, function (res) {
if(!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
return;
}
...
withAccessToken = function () { [native code] }
...
### withAccessToken
*This is a non-standard api and does not exist in the official client side FB JS SDK.*
Using `FB.extend` this returns a new FB object that inherits the same options but has an accessToken specific to it set.
```js
var fb = FB.withAccessToken('access_token');
```
### getAccessToken
*Unlike `setAccessToken` this is a standard api and exists in FB JS SDK.*
```js
FB.setAccessToken('access_token');
...
function FacebookApiException(res) { this.name = 'FacebookApiException'; this.message = (0, _stringify2.default)(res || {}); this.response = res; Error.captureStackTrace(this, this.constructor.name); }
...
return buffer.toString('utf8');
},
nodeifyCallback = function nodeifyCallback(originalCallback) {
// normalizes the callback parameters so that the
// first parameter is always error and second is response
return function (res) {
if (!res || res.error) {
originalCallback(new _FacebookApiException2.default(res));
} else {
originalCallback(null, res);
}
};
};
var _opts = (0, _symbol2.default)('opts');
...
function Facebook(opts, _internalInherit) { (0, _classCallCheck3.default)(this, Facebook); if (_internalInherit instanceof Facebook) { this[_opts] = (0, _create2.default)(_internalInherit[_opts]); } else { this[_opts] = (0, _create2.default)(defaultOptions); } if (typeof opts === 'object') { this.options(opts); } }
...
## Library usage
Libraries can isolate themselves from the options belonging to the default `FB` by creating an instance of the `Facebook` class.
```javascript
// ES5
var FB = require('fb'),
fb = new FB.Facebook(options);
// ES2015 w/ require()
var {Facebook, FacebookApiException} = require('fb'),
fb = new Facebook(options);
// ES2015 w/ import through Babel
import {Facebook, FacebookApiException} from 'fb';
...
function FacebookApiException(res) { this.name = 'FacebookApiException'; this.message = (0, _stringify2.default)(res || {}); this.response = res; Error.captureStackTrace(this, this.constructor.name); }
n/a