Zum Inhalt springen

Der Computer Blog

Alles über die Informatik & Co.

  • Programmierung
    • HTML5
      • CSS3 Animationen
      • CSS3 Transitionen
      • CSS3 Performance
    • JavaScript
      • Best Practices
    • JEE Tutorial
    • MySQL
    • Python
    • Windows Phone
    • Windows Store
  • Spicker
    • Linux Befehle
    • MySQL Befehle
    • Reguläre Ausdrücke
  • Tools
    • Countdown-Zähler
    • Passwort-Generator
    • Prozentrechner
    • Sprite-Generator
  • Empfehlungen
    • Firefox Plugins
    • Software
  • E-Learning

Schlagwort: scope

Facebook JavaScript SDK made simple

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>

<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

Veröffentlicht am 28. April 201228. April 2012Kategorien JavaScriptSchlagwörter authentication, Facebook, facebook-jssdk, fb-root, FB.init, FB.login, JavaScript, js, permissions, scope, SDKSchreibe einen Kommentar zu Facebook JavaScript SDK made simple
Stolz präsentiert von WordPress