Git Product home page Git Product logo

facebook-node-sdk's Introduction

NodeJS Library for Facebook Build Status

With facebook-node-sdk you can now easily write the same code and share between your server (nodejs) and the client (Facebook Javascript SDK).

This SDK will report usage of which AppID is using it directly to Facebook.

Author: Thuzi

License: Apache v2

Installing facebook-node-sdk

npm install fb
var FB = require('fb');

Running Samples

Update appId and appSecret in samples/scrumptious/config.js

npm install
cd samples/scrumptious
npm install
node app.js

Graph Api

Get

var FB = require('fb');

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);
});

Passing Parameters

var FB = require('fb');

FB.api('4', { fields: ['id', 'name'] }, function (res) {
  if(!res || res.error) {
    console.log(!res ? 'error occurred' : res.error);
    return;
  }
  console.log(res.id);
  console.log(res.name);
});

Post

var FB = require('fb');
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;
  }
  console.log('Post Id: ' + res.id);
});

Delete

var FB = require('fb');
FB.setAccessToken('access_token');

var postId = '1234567890';
FB.api(postId, 'delete', function (res) {
  if(!res || res.error) {
    console.log(!res ? 'error occurred' : res.error);
    return;
  }
  console.log('Post was deleted');
});

Facebook Query Language (FQL)

Query

var FB = require('fb');
FB.setAccessToken('access_token');

FB.api('fql', { q: 'SELECT uid FROM user WHERE uid=me()' }, function (res) {
  if(!res || res.error) {
    console.log(!res ? 'error occurred' : res.error);
    return;
  }
  console.log(res.data);
});

Multi-query

var FB = require('fb');
FB.setAccessToken('access_token');

FB.api('fql', { q: [
  'SELECT uid FROM user WHERE uid=me()',
  'SELECT name FROM user WHERE uid=me()'
] }, function(res) {
  if(!res || res.error) {
    console.log(!res ? 'error occurred' : res.error);
    return;
  }
  console.log(res.data[0].fql_result_set);
  console.log(res.data[1].fql_result_set);
});

Named Multi-query

var FB = require('fb');
FB.setAccessToken('access_token');

FB.api('fql', { q : {
  id: 'SELECT uid FROM user WHERE uid=me()',
  name: 'SELECT name FROM user WHERE uid IN (SELECT uid FROM #id)'
} }, function(res) {
  if(!res || res.error) {
    console.log(!res ? 'error occurred' : res.error);
    return;
  }
  console.log(res.data[0].fql_result_set);
  console.log(res.data[1].fql_result_set);
});

Batch Requests

var FB = require('fb');
FB.setAccessToken('access_token');

var extractEtag;
FB.api('', 'post', { 
    batch: [
        { method: 'get', relative_url: '4' },
        { method: 'get', relative_url: 'me/friends?limit=50' },
        { method: 'get', relative_url: 'fql?q=' + encodeURIComponent('SELECT uid FROM user WHERE uid=me()' ) }, /* fql */
        { method: 'get', relative_url: 'fql?q=' + encodeURIComponent(JSON.stringify([
                    'SELECT uid FROM user WHERE uid=me()',
                    'SELECT name FROM user WHERE uid=me()'
                ])) }, /* fql multi-query */
        { method: 'get', relative_url: 'fql?q=' + encodeURIComponent(JSON.stringify({
                    id: 'SELECT uid FROM user WHERE uid=me()',
                    name: 'SELECT name FROM user WHERE uid IN (SELECT uid FROM #id)'
                })) }, /* named fql multi-query */
        { method: 'get', relative_url: '4', headers: { 'If-None-Match': '"7de572574f2a822b65ecd9eb8acef8f476e983e1"' } }, /* etags */
        { method: 'get', relative_url: 'me/friends?limit=1', name: 'one-friend' /* , omit_response_on_success: false */ },
        { method: 'get', relative_url: '{result=one-friend:$.data.0.id}/feed?limit=5'}
    ]
}, function(res) {
    var res0, res1, res2, res3, res4, res5, res6, res7,
        etag1;

    if(!res || res.error) {
        console.log(!res ? 'error occurred' : res.error);
        return;
    }

    res0 = JSON.parse(res[0].body);
    res1 = JSON.parse(res[1].body);
    res2 = JSON.parse(res[2].body);
    res3 = JSON.parse(res[3].body);
    res4 = JSON.parse(res[4].body);
    res5 = res[5].code === 304 ? undefined : JSON.parse(res[5].body);   // special case for not-modified responses
                                                                        // set res5 as undefined if response wasn't modified.
    res6 = res[6] === null ? null : JSON.parse(res[6].body);
    res7 = res6 === null ? JSON.parse(res[7].body) : undefined; // set result as undefined if previous dependency failed

    if(res0.error) {
        console.log(res0.error);
    } else {
        console.log('Hi ' + res0.name);
        etag1 = extractETag(res[0]); // use this etag when making the second request.
        console.log(etag1);
    }

    if(res1.error) {
        console.log(res1.error);
    } else {
        console.log(res1);
    }

    if(res2.error) {
        console.log(res2.error);
    } else {
        console.log(res2.data);
    }

    if(res3.error) {
        console.log(res3.error);
    } else {
        console.log(res3.data[0].fql_result_set);
        console.log(res3.data[1].fql_result_set);
    }

    if(res4.error) {
        console.log(res4.error);
    } else {
        console.log(res4.data[0].fql_result_set);
        console.log(res4.data[0].fql_result_set);
    }

    // check if there are any new updates
    if(typeof res5 !== "undefined") {
        // make sure there was no error
        if(res5.error) {
            console.log(error);
        } else {
            console.log('new update available');
            console.log(res5);
        }
    }
    else {
        console.log('no updates');
    }

    // check if dependency executed successfully    
    if(res[6] === null) {
        // then check if the result it self doesn't have any errors.
        if(res7.error) {
            console.log(res7.error);
        } else {
            console.log(res7);
        }
    } else {
        console.log(res6.error);
    }
});

extractETag = function(res) {
    var etag, header, headerIndex;
    for(headerIndex in res.headers) {
        header = res.headers[headerIndex];
        if(header.name === 'ETag') {
            etag = header.value;
        }
    }
    return etag;
};

Post

var FB = require('fb');
FB.setAccessToken('access_token');

var message = 'Hi from facebook-node-js';
FB.api('', 'post', {
    batch: [
        { method: 'post', relative_url: 'me/feed', body:'message=' + encodeURIComponent(message) }
    ]
}, function (res) {
    var res0;

    if(!res || res.error) {
        console.log(!res ? 'error occurred' : res.error);
        return;
    }

    res0 = JSON.parse(res[0].body);

    if(res0.error) {
        console.log(res0.error);
    } else {
        console.log('Post Id: ' + res0.id);
    }
});

OAuth Requests

This is a non-standard behavior and does not work in the official client side FB JS SDK.

facebook-node-sdk is capable of handling oauth requests which return non-json responses. You can use it by calling api method.

Get facebook application access token

var FB = require('fb');

FB.api('oauth/access_token', {
    client_id: 'app_id',
    client_secret: 'app_secret',
    grant_type: 'client_credentials'
}, function (res) {
    if(!res || res.error) {
        console.log(!res ? 'error occurred' : res.error);
        return;
    }
    
    var accessToken = res.access_token;
});

Exchange code for access token

var FB = require('fb');

FB.api('oauth/access_token', {
    client_id: 'app_id',
    client_secret: 'app_secret',
    redirect_uri: 'http://yoururl.com/callback',
    code: 'code'
}, function (res) {
    if(!res || res.error) {
        console.log(!res ? 'error occurred' : res.error);
        return;
    }

    var accessToken = res.access_token;
    var expires = res.expires ? res.expires : 0;
});

You can safely extract the code from the url using the url module. Always make sure to handle invalid oauth callback as well as error.

var url = require('url');
var FB = require('fb');

var urlToParse = 'http://yoururl.com/callback?code=.....#_=_';
var result = url.parse(urlToParse, true);
if(result.query.error) {
    if(result.query.error_description) {
        console.log(result.query.error_description);
    } else {
        console.log(result.query.error);
    }
    return;
} else if (!result.query.code) {
    console.log('not a oauth callback');
    return;
}

var code = result.query.code;

Extend expiry time of the access token

var FB = require('fb');

FB.api('oauth/access_token', {
    client_id: 'client_id',
    client_secret: 'client_secret',
    grant_type: 'fb_exchange_token',
    fb_exchange_token: 'existing_access_token'
}, function (res) {
    if(!res || res.error) {
        console.log(!res ? 'error occurred' : res.error);
        return;
    }
    
    var accessToken = res.access_token;
    var expires = res.expires ? res.expires : 0;
});

Legacy REST Api

Although Legacy REST Api is supported by facebook-node-sdk, it is highly discouraged to be used, as Facebook is in the process of deprecating the Legacy REST Api.

Get

var FB = require('fb');

FB.api({ method: 'users.getInfo', uids: ['4'], fields: ['uid', 'name'] }, function (res) {
    if(!res || res.error_msg) {
        console.log(!res ? 'error occurred' : res.error_msg);
        return;
    }

    console.log('User Id: ' + res[0].uid);
    console.log('Name: ' + res[0].name);
});

Post

var FB = require('fb');
FB.setAccessToken('access_token');

var message = 'Hi from facebook-node-sdk';
FB.api({ method: 'stream.publish', message: message }, function (res) {
    if(!res || res.error_msg) {
        console.log(!res ? 'error occurred' : res.error_msg);
        return;
    }
    
    console.log(res);
});

Delete

var FB = require('fb');
FB.setAccessToken('access_token');

var postId = '.....';
FB.api({ method: 'stream.remove', post_id: postId }, function (res) {
    if(!res || res.error_msg) {
        console.log(!res ? 'error occurred' : res.error_msg);
        return;
    }
    
    console.log(res);
});

Access Tokens

setAccessToken

This is a non-standard api and does not exist in the official client side FB JS SDK.

var FB = require('fb');
FB.setAccessToken('access_token');

If you want to use the api compaitible with FB JS SDK, pass access_token as parameter.

FB.api('me', { fields: ['id', 'name'], access_token: 'access_token' }, function (res) {
    console.log(res);
}

getAccessToken

Unlike setAccessToken this is a standard api and exists in FB JS SDK.

var FB = require('fb');
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

options

This is a non-standard api and does not exist in the official client side FB JS SDK.

When this method is called with no parameters it will return all of the current options.

var FB = require('fb');
var options = FB.options();

When this method is called with a string it will return the value of the option if exists, null if it does not.

var timeout = FB.options('timeout');

When this method is called with an object it will merge the object onto the previous options object.

FB.options({accessToken: 'abc'}); //equivalent to calling setAccessToken('abc')
FB.options({timeout: 1000, accessToken: 'XYZ'}); //will set timeout and accessToken options
var timeout = FB.options('timeout'); //will get a timeout of 1000
var accessToken = FB.options('accessToken'); //will get the accessToken of 'XYZ'

The existing options are:

  • 'accessToken' string representing the facebook accessToken to be used for requests. This is the same option that is updated by the setAccessToken and getAccessToken methods.
  • 'appSecret' string representing the facebook application secret.
  • 'proxy' string representing an HTTP proxy to be used. Support proxy Auth with Basic Auth, embedding the auth info in the uri: 'http://[username:password@]proxy[:port]' (parameters in brackets are optional).
  • 'timeout' integer number of milliseconds to wait for a response. Requests that have not received a response in X ms. If set to null or 0 no timeout will exist. On timeout an error object will be returned to the api callback with the error code of 'ETIMEDOUT' (example below).

'scope' and 'redirectUri' have been whitelisted in options for convenience. These value will not be automatically added when using any of the sdk apis unlike the above options. These are whitelisted so you can use it to pass values using the same FB object.

version

This is a non-standard api and does not exist in the official client side FB JS SDK.

Gets the string representation of the facebook-node-sdk library version.

var FB = require('fb');
var version = FB.version;

Parsing Signed Request

parseSignedRequest

This is a non-standard api and does not exist in the official client side FB JS SDK.

var FB = require('fb');

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;
}

Note: parseSignedRequest will return undefined if validation fails. Always remember to check the result of parseSignedRequest before accessing the result.

If you already set the appSeceret in options, you can ignore the second parameter when calling parseSignedRequest. If you do pass the second parameter it will use the appSecret passed in parameter instead of using appSecret from options.

If appSecret is absent, parseSignedRequest will throw an error.

var FB = require('fb');
FB.options({ 'appSecret': 'app_secret'});

var signedRequestValue = 'signed_request_value';

var signedRequest  = FB.parseSignedRequest(signedRequestValue);
if(signedRequest) {
    var accessToken = signedRequest.oauth_token;
    var userId = signedRequest.user_id;
    var userCountry = signedRequest.user.country;
}

Error handling

Note: facebook is not consistent with their error format, and different systems can fail causing different error formats

Some examples of various error codes you can check for:

  • 'ECONNRESET' - connection reset by peer
  • 'ETIMEDOUT' - connection timed out
  • 'ESOCKETTIMEDOUT' - socket timed out
  • 'JSONPARSE' - could not parse JSON response, happens when the FB API has availability issues. It sometimes returns HTML
var FB = require('fb');
FB.options({timeout: 1, accessToken: 'access_token'});

FB.api('/me', function (res) {
    if(res && res.error) {
        if(res.error.code === 'ETIMEDOUT') {
            console.log('request timeout');
        }
        else {
            console.log('error', res.error);
        }
    }
    else {
        console.log(res);
    }
});

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 FB.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

var FB = require('fb');

FB.napi('4', function(error, response) {
    if(error) {
        if(error.response.error.code === 'ETIMEDOUT') {
            console.log('request timeout');
        }
        else {
            console.log('error', error.message);
        }
    } else {
        console.log(response);
    }
});

FB.napi was added especially to make it easier to work with async control flow libraries.

Here are some examples of using facebook-node-sdk with Step.

You will need to install step.

npm install step

FB.api with Step

var FB      = require('fb'),
    Step    = require('step');

Step(
    function getUser() {
        var self = this;
        FB.api('4', function(res) {
            if(!res || res.error) {
                self(new Error('Error occured'));
            } else {
                self(null, res);
            }
        });
    },
    function processResult(err, res) {
        if(err) throw err;
        console.log(res);
    }
);

FB.napi with Step

Simplified version of facebook-node-sdk async callbacks using FB.napi.

var FB      = require('fb'),
    Step    = require('step');

Step(
    function getUser() {
        FB.napi('4', this);
    },
    function processResult(err, res) {
        if(err) throw err;
        console.log(res);
    }
);

facebook-node-sdk's People

Contributors

cruppert avatar etticat avatar jimzim avatar jschluchter avatar louisameline avatar mostlygeek avatar oazais avatar prabirshrestha avatar sodoku avatar stowns avatar tk120404 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

facebook-node-sdk's Issues

Explanation on "whitelisted" options

Hello and thank you for this library.

I do not understand the following paragraph of the documentation, especially the third sentence. What do you mean by whitelisted ? Thank you.

'scope' and 'redirectUri' have been whitelisted in options for convenience. These value will not be automatically added when using any of the sdk apis unlike the above options. These are whitelisted so you can use it to pass values using the same FB object.

Posting as a site

Hey.

I am trying to figure out how I would post as a site. At the moment, I want to pick up a new blog post from a site in a worker process and if the blog post does not exist on my facebook page, it should post there.

As said, I am rather new to using the SDK, but would just like to post. Later, I may want to edit, if the post changed.

Kind regards, Ingwie.

the demo /announce, run error OAuthException

FB.getLoginUrl({ scope: 'user_about_me,publish_actions', state: encodeURIComponent(JSON.stringify(parameters)) });

but,If I use other user(not application owner),It's has an error:

{ error:
{ message: '(#200) Requires extended permission: publish_actions',
type: 'OAuthException',
code: 200 } }

facebook-node-sdk with browserify

Is this suppose to work out of the box?

I'd like to replace my fb sdk async call with this & browserify, but I get a node_modules error on the client side.

I'm just asking before digging further.

allow to set user-agent

useful when using etags. also should be set by default. pass node version?

FB.options({'user-agent': 'thuzi_nodejssdk/0.0.7 (facebook-node-sdk)'});

Express 500 FacebookApiException

I'm receiving the message below after I have log to facebook.

Express
500 FacebookApiException: {"error":{"code":"EHOSTUNREACH","errno":"EHOSTUNREACH","syscall":"connect"}}

Is this repository maintained?

I see bunch of pull requests waiting. Seems like we have to fork louisameline's fork and merge manually some of the pull requests

scrumptious sample not working

Step to reproduce:

  1. Login to Facebook and grant all requested permissions
  2. select all the food, place, and friends
  3. press Announce
  4. allow all the requested post dialog by Facebook
  5. expected an open graph action to be posted on my page

but instead, get OAuthException: An unknown error has occured
the error: https://gist.github.com/JiboStore/5693636/61d411d860ad1c6c003e772cf2d8004ed4b08347
or pasted as is:

access_token = CAAB2dKc4ZCMEBAAn2vCajKjEJUK5DGQ2urcUIij2wtLbvg6fmbUmEQW4YKxj5QZAemDyx8yLXKyLlZBcZBAeUMIhFUzmul8G45k5h0hBZCu3R07tCZC4QZBQRElACOKYh48CDUodIA4P7t4HITHvwgZC
{ error:
{ message: 'An unknown error has occurred.',
type: 'OAuthException',
code: 1 } }
JSON Stringify: {"error":{"message":"An unknown error has occurred.","type":"OAuthException","code":1}}
POST /announce 500 452ms - 486
{ meal: 'http://nodescrumptious.azurewebsites.net/meals/cheeseburger',
place: '361771023937832',
tags: '510683132',
access_token: 'CAAB2dKc4ZCMEBAIoHzPLVSv8DWuXY8UZCMzZABtjA0wCMfwBEK7lVuy3ZBhXON3Tv7cY75VBI4BScOl3HSt285h5g01xxDJ9x5T5nZBzDIBgZBiE0twB9RcYDcUetNYsGGxo627upZA7clCZBNsYknAFvysNyLSDJbcZD' }
{ error:
{ message: 'An unknown error has occurred.',
type: 'OAuthException',
code: 1 } }
GET /login/callback?code=AQCMoSVxtJTPFjQDluAootk4oztVvCLTuo8nmoeSUUlohyWg9_uht_aUVRbBQd-R9hsDL1wr4HQz_L4rC_k1rorJwhZIOeZI5yRQ1trSLgmNJqpaCJ4s5dFp0hyzAZ9CbPNwNf60N1JORQP7u2LIvnjfNoytzud4KgU1SnmvHmzSFiOLl3gNS5MViwOPOyf-oJWgiVMObfxAEybTk77aziDTRUwbq_ElKZcp5Efi5bCweg36Zm-LEoeWnU9vWDnpk9wuadQaPkF9EA_vgFPHYpVYjZTaS5M3JjeIwR6scnx8b2OeKAWDu9GT-ZISxLQXZdI&state=%7B%22meal%22%3A%22http%3A%2F%2Fnodescrumptious.azurewebsites.net%2Fmeals%2Fcheeseburger%22%2C%22place%22%3A%22361771023937832%22%2C%22tags%22%3A%22510683132%22%7D 500 1362ms - 113

Access Token Question

var FB = require('fb');

FB.api('/v2.1/oauth/access_token', {
    client_id: 'id',
    client_secret: 'secret',
    grant_type: 'client_credentials'
}, function (res) {
    if(!res || res.error) {
        console.log(!res ? 'error occurred' : res.error);
        return;
    }

    var accessToken = res.access_token;
    FB.setAccessToken(accessToken);
    console.log(res);
});

FB.api('/v2.1/me/pokes', function (res) {
  if(!res || res.error) {
   console.log(!res ? 'error occurred' : res.error);
   return;
  }
});

Hi, I'm trying to make something like the above code work, but I can't seem to get the access token to be returned to me. When I log the accessToken value its just my client_secret appended to my client_id. This doesn't seem right. How do I get the above code to work as expected? Is this my fault or a bug with this repo?

Can't reset access token in-state

Running something where I need to change the access token on the fly, but they way the code is, once it's set, it never looks for it again to change.

Something like this should do the trick

if(options('accessToken') && params.access_token != options('accessToken')) {
...etc

no response when trying to post FB.api( 'me',...

Not sure if I just did it wrong - I've had other requests work fine 'me/friends' or 'me/albums' - but when I tried just requesting 'me' I never got a response. Can you please verify if this works for you?

Extend access_token

Hey,

I want to extend the validity of a long access_token using this method.

When I try, the expires doesn't look to get longer:

expires :  5176585  =  59.91417824074074 days
expires :  5176572  =  59.914027777777775 days
expires :  5176562  =  59.913912037037036 days

Is there something I'm wrong with?

Thanks a lot,
Philmod

Get all the albums from facebook using nodejs and express

I need to get all the albums from facebook using nodejs and express.I am using passport to authenticate the user.

passport.use(new FacebookStrategy( {
clientID : FACEBOOK_APP_ID,
clientSecret : FACEBOOK_APP_SECRET,
callbackURL : FACEBOOK_CALL_BACK_URL,
profile : true
}, function(accessToken, refreshToken, profile, done) {
FB_ACCESS_TOKEN = accessToken;
process.nextTick(function() {
console.log("FB_ACCESS_TOKEN : " + FB_ACCESS_TOKEN);
return done(null, profile);
});
}));

In call i am requesting for scope user_status,user_photos and offline_access

app.get('/auth/facebook', passport.authenticate('facebook'), {
scope : [ 'user_status', 'user_photos','offline_access']
}, function(req, res) {
});

To get all albums I am using

app.get('/albums', function(req, res) {
FB.setAccessToken(FB_ACCESS_TOKEN);
console.log("FB_ACCESS_TOKEN @@ : " + FB.getAccessToken());
FB.api('/me/albums', function(resp) {
console.log("Albums " + JSON.stringify(resp));
});
});

But in console i am getting

Albums {"data":[]}

NOTE : I checked the fb javascript example fbrell.com/fb.api/photo-albums In that the scope specified are "user_photos,friends_photos,user_photo_video_tags,friends_photo_video_tags".I just want the photos and so i used user_photos

Any help??

Publish new version to npm

The newest version of this appears to be 0.7.3, however only 0.7.0 has been published to npm.

So if you npm install fb you get an old version with no appsecret_proof support.

Used split() on a non-string

fb.js line 320:

Current: split = body[key].split('=');

Suggested change: split = body[key].toString().split('=');

It currently gives me this error:

/node_modules/fb/fb.js:321
                split = body[key].split('=');
                                  ^
TypeError: Object function () {
    var i = this.length, j, temp;
    if ( i == 0 ) return this;
    while ( --i ) {
        j = Math.floor( Math.random() * ( i + 1 ) );
        temp = this[i];
        this[i] = this[j];
        this[j] = temp;
    }
    return this;
} has no method 'split'

Casting the response to a string solves the issue.

the example "scrumptious" doesnt work

it's returning

{

"error": {
    "message": "(#100) problem with action type (360109757437618)",
    "type": "OAuthException",
    "code": 100
}

}
when trying to post...

Debug request calls

Is there any way to activate verbose request logs? I tried to set an environment variable as stated on request wiki, but it does not log anything...

Thank you

v2.0 is not working with your api.

Hello, i tried your api from npm, and i found that your api is not working with v2.0. did you added some extension on it? or i have to manually edit your library by appending "v2.0" in all endpoints?

Please reply.

What is flow of getting access_token on server-side?

Actually, when you use :

FB.api('oauth/access_token', {
    client_id:     'id here',
    client_secret: 'client secret here',
    grant_type:    'client_credentials'
  }, function (fbres) {
    if (!fbres || fbres.error) {
      totalResult.push(fbres);
});

something like this, you get only id|string (separated by pipe). But its not enough to fully use this API further. We need to get session id from FB api?

How to get it? Can you please provide normal example.

Thank you.

Does uploading image is working ?

Does this call is working ?

     FB.api(pageid + '/photos', 'post', { message: body, source: buff, }, function (resf) {
                    if (!resf || resf.error) {
                        console.log(!resf ? 'error occurred' : resf.error);
                        return;
                    }
                    console.log( resf);
                    res.send(resf);
                });

Does the oauth with fileuplad is working ?

 FB.api('oauth/access_token', {
    client_id: clientid,
    client_secret: clientsecret,
    redirect_uri: redirecturi,
    code: code,
    scope: scope,
    fileUpload : true,
    }

add oauth 2.0 api request features

FB.api should be able to handle calls to https://graph.facebook.com/oauth These return querystring format instead of json - a=b&c=d. errors still return json. So extra care must be taken. this can be accomplished by checking for status code "200 OK", path starting with "/oauth" and content-type containing text/plain.

Does not support images

When requesting an image, either an url or a buffer should be returned. Instead the JSON parser fails and returns an error.

FB.api("/me/picture", {access_token: token}, cb);

remove if(cb)

cb = cb || function() {}; cb will never be undefined. so remove checks

Option to add channelUrl on facebook sdk initialisation

I wanted to set channelUrl on initialisation. I see there is no such feature in this package. I think this feature is essential to solve a issue while loading a facebook video.

A short note on the issue when embedding a facebook video in iframe tag. Firefox browser console is reporting an error :"Error: Permission denied to access property 'toString' ". There is no such issue in Chrome. I see this SO link http://stackoverflow.com/questions/15518450/how-to-fix-the-error-i-am-getting-while-loading-the-facebook-javascript-sdk . I wanted to try this 'channelUrl' fix.
Also, in this SO link http://stackoverflow.com/questions/13100611/replace-url-from-youtube-to-embed-code-error-permission-denied-to-access-prop it's reported as a browser specific issue, I think this can be fixed.

HTML:

<iframe width="720" height="1280" frameborder="0" src="https://www.facebook.com/video/embed?video_id=627802933963417">

posting images to event/album using graph api

This library is very useful, and I'm using it to post events on facebook through the api. I'd like to POST an image with the event, but doing this seems tricky...

The following curl command works for posting an event with an image (assuming the token has all the required permissions):

curl -F 'access_token=<insertAccessToken>' \
-F 'name=Test Event 1' \
-F 'start_time=2013-01-20T12:00:00+0000' \
-F '@newImageName.png=@/Users/<mycomputer>/Sites/Node/facebook/image.png' \
http://graph.facebook.com/me/events

I found numerous people on stackoverflow.com looking for answers using the PHP facebook-sdk. Most seemed successful with both events and photos to albums:
http://stackoverflow.com/questions/2718610/upload-photo-to-album-with-facebooks-graph-api

The key is setting the image as a separate multipart request and passing that in the POST. I assume this is what the curl -F '@newImageName.png=@/path//to/image.png' does before POSTing the event. I want to achieve this multipart-formatting image post from my machine to FB using this library.

This seems like a good start to adding this feature:
mscheibe/python-sdk@13d5849

I looked into the request.js library and it seems to support multipart posts also, I just don't know exactly how to go about implementing this. I might just end up adding the Node-Curl wrapper from https://github.com/chriso/curlrequest, but that seems a bit overkill.

Any help would be great.

doesn't allow fb_exchange_token

When I'm trying to exchange token, I need to send fb_exchange_token but Facebook response is

{ message: 'fb_exchange_token parameter not specified',
type: 'OAuthException',
code: 1 }

Still having issues with appsecret_proof

I have this error , when I try to make a call to fb.
I haven't updated for while, but last this was wrking before 4 weeks. I saw the error and thought that if I install the latest version it will fix it, but it's not the case

Invalid appsecret_proof provided in the API argument

500 FacebookApiException:

I run the example,

npm install
cd samples/scrumptious
npm install
node app.js

and I make click on the button login of facebook, an when retrieved from facebook, this is the error that showme.

500 FacebookApiException: {"error":{"message":"Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request","type":"OAuthException","code":100}}

This exactly happend with other libraries of facebook sdk, I don't know if is a bug of this library or if is some that I make wrong.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.