SORU
23 AĞUSTOS 2010, PAZARTESİ


Nasıl'un FB facebook algılamak için.başlatma tamamlandı

Eski JS SDK FB adlı bir fonksiyon vardı.ensureİnit. Yeni SDK gibi işlev... nasıl tam olarak başlatılır kadar apı çağrıları yapmak istemiyorum emin olabilir miyim? görünmüyor

Her sayfanın üst kısmında bu vardır:

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId  : '<?php echo $conf['fb']['appid']; ?>',
      status : true, // check login status
      cookie : true, // enable cookies to allow the server to access the session
      xfbml  : true  // parse XFBML
    });
    FB.Canvas.setAutoResize();
  };

  (function() {
    var e = document.createElement('script');
    e.src = document.location.protocol   '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
  }());
</script>

CEVAP
23 AĞUSTOS 2010, PAZARTESİ


Jan 04, 2012 güncelleştirin

Sadece sağ FB.init() FB.init() şimdi uyumsuz gibi görünüyor önce, sonra FB-bağımlı yöntemler (örneğin FB.getAuthResponse()) çağırmak yok gibi görünüyor. FB.getLoginStatus() tepki kodunuzu kaydırma API tam olarak hazır olduğunda tespit hile yapmak gibi görünüyor:

window.fbAsyncInit = function() {
    FB.init({
        //...
    });

    FB.getLoginStatus(function(response){
        runFbInitCriticalCode(); 
    });

};  

ya da eğer fbEnsureInit() aşağıdan uygulaması:

window.fbAsyncInit = function() {
    FB.init({
        //...
    });

    FB.getLoginStatus(function(response){
        fbApiInit = true;
    });

};  

Orijinal Yazı:

Eğer sadece FB başlatıldığında bazı komut dosyası çalıştırmak istiyorsanız fbAsyncInit içinde bazı geri arama fonksiyonu koyabilirsiniz:

  window.fbAsyncInit = function() {
    FB.init({
      appId  : '<?php echo $conf['fb']['appid']; ?>',
      status : true, // check login status
      cookie : true, // enable cookies to allow the server to access the session
      xfbml  : true  // parse XFBML
    });
    FB.Canvas.setAutoResize();

    runFbInitCriticalCode(); //function that contains FB init critical code
  };

Eğer FB tam yerine isterseniz.ensureİnit sonra resmi değiştirme (büyük hata ımo) yok gibi kendi başına bir şeyler yazmak gerekir. Ben kullanın:

  window.fbAsyncInit = function() {
    FB.init({
      appId  : '<?php echo $conf['fb']['appid']; ?>',
      status : true, // check login status
      cookie : true, // enable cookies to allow the server to access the session
      xfbml  : true  // parse XFBML
    });
    FB.Canvas.setAutoResize();

    fbApiInit = true; //init flag
  };

  function fbEnsureInit(callback) {
        if(!window.fbApiInit) {
            setTimeout(function() {fbEnsureInit(callback);}, 50);
        } else {
            if(callback) {
                callback();
            }
        }
    }

Kullanımı:

fbEnsureInit(function() {
    console.log("this will be run once FB is initialized");
});

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • CaptainDisillusion

    CaptainDisil

    18 EYLÜL 2007
  • spederson7

    spederson7

    17 Temmuz 2006
  • Videogamerz | Call of Duty

    Videogamerz

    5 NİSAN 2012