To work with the Facebook API you have to load the Facebook JavaScript SDK, initialize your Facebook application, authenticate the user and request an access token to then send the final Facebook API calls. In this long process chain much can go wrong. Especially because the calls happen all asnychron. You have to work with the correct callback mechanisms to reach the goal. To hide this mechanism and to make the Facebook API easier to use, I have created an abstraction, with which you can work much easier, as you can see here:
<script src="./js/simple-facebook.js"></script> <script> // Setup var fb = new SimpleFacebook(); fb.setAppId('255100001240698'); fb.setLocale('de_DE'); fb.setPermissions('email,user_about_me,friends_about_me,publish_actions'); // Usage fb.showUsersName(); fb.showUsersLink(); </script> |
Doesn’t it look great? No more need to include a fb-root
tag or many JavaScript snippets. All you need is the simple-facebook.js
file, which can be expanded depending on your needs. Here is a basic version, which illustrates the concept:
Facebook JavaScript SDK made simple weiterlesen