2012-06-10 92 views
4

我正在使用Sencha創建應用程序,我需要將Facebook登錄集成到其中。當我點擊「用facebook登錄」按鈕時,如果用戶沒有登錄Facebook,它應該顯示一個彈出框來輸入Facebook的電子郵件ID和密碼,否則如果用戶已經登錄它應該只是登錄在Facebook認證。我如何使用sencha touch來實現這一點。請幫忙 。如果提供了此功能的代碼將會很有幫助。感謝「用facebook登錄」代碼!集成到應用程序

回答

4

首先,您必須使用臉譜(please follow this link)創建JavaScript SDK應用程序。應用程序創建後,您將擁有APP ID。與Facebook登錄,當您創建的Facebook應用程序下的網站:然後添加以下代碼到app.js

Ext.application({ 
    name: 'FBLogin', 
    launch: function() { 
     Ext.create('Ext.container.Viewport', { 
      items:[ 
       { 
        xtype: 'panel', 
        html: '<center><div id="fblogin" class="fb-login-button">Login with Facebook</div></center>' 
       } 
      ], 
      listeners:{ 
       render: function(obj, eOpts){ 
        window.fbAsyncInit = Ext.bind(this.onFacebookInit, this); 
        (function(d){ 
         var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
         if (d.getElementById(id)) {return;} 
         js = d.createElement('script'); js.id = id; js.async = true; 
         js.src = "//connect.facebook.net/en_US/all.js"; 
         ref.parentNode.insertBefore(js, ref); 
        }(document)); 
       } 
      }, 
      onFacebookInit: function(){ 
       console.log('onFacebookInit'); 
       var me = this; 
       FB.init({ 
        appId  : 'YOUR_APP_ID', 
        status  : true, 
        xfbml  : true 
       }); 
       FB.Event.subscribe('auth.authResponseChange', Ext.bind(me.onFacebookAuthResponseChange, me)); 
      }, 
      onFacebookAuthResponseChange: function(response){ 
       this.down('panel').setVisible(false); 
       alert("Success fully Logged in"); 
      } 
     }); 
    } 
}); 

將會有一個叫場「SITEURL」。這應該指向你的網絡應用程序的URL。 (例如:http://example.com

+0

不錯,但這會打開一個彈出窗口,任何想法如何在應用程序中打開模式窗口? – Moak

+0

雖然它在Chrome中起作用。此方法不適用於原生Android Sencha APP – Moak

4

你可以嘗試使用Phonegap Facebook Connect Plugin 0.4.0(穩定版) 和使用Phonegap Plugin Build建立包爲Android,iPhone,Windows手機,blackbery等。

//on Device Ready 
    FB.init({ appId: "appid", nativeInterface: CDV.FB, useCachedDialogs: false }); 
    // call for native app if there else give a popup for login 
    FB.login(
          function(response) { 
          if (response.session) { 
          alert('logged in'); 
          } else { 
          alert('not logged in'); 
          } 
          }, 
          { scope: "email" } 
          ); 

中序與煎茶這就需要添加三個腳本文件CDV-插件-FB-connect.js,phonegap.js和Facebook-JS-sdk.js在index.html文件並添加config.xml中整合文件項目建立電話差距構建構建本機應用程序(不使用煎茶本地包裝)。對於config.xml文件中的配置請參見本config Help 如果有任何疑問,請參閱github上例如here 希望工程

相關問題