1

As I've said in my previous posts, I'm learning how to use Node JS & Sails JS. Now I'm trying to integrate facebook's graph API in my web application. I searched and went through facebook's developer's site but somehow I'm still finding a hard time understanding what I should do. I already have an app in facebook, so I already have the app id and so on.

Now, I already have a facebook login button in my login.ejs under views

 <fb:login-button autologoutlink="true" onlogin="OnRequestPermission();">
 </fb:login-button>

And the facebook javascript sdk which is loaded in my layout.ejs

<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'myAPPID',
      xfbml      : true,
      version    : 'v2.3',
      status     : true
    });
  };

  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>

Question is, how will I be able to get the user access token and what is the best way to store it? And how will I be able to use the graph API in my controller? Should I install a node module or create my own? Also what is the best approach in using API's other than graph api, like twitter's api, alongside node & sails?

Thanks!

1 Answer 1

0

You can obtain the access token by registering a callback method to be executed on the Facebook JAvaScript SDK's auth.login event. This is documented [here].(https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.3)

But in fact you don't need to handle or even store the access token if you are using the JavaScript SDK. You can just call e.g. FB.api(path, method, params, callback) to make Graph API requests, and that will make sure an access token is sent as part of the request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.