2

我想將facebook登錄按鈕集成到我的網站。用戶只能使用他/她的Facebook帳戶登錄。我對任何有關用戶的其他信息不感興趣。在Flash網站創建Facebook登錄按鈕

但我有點困惑...我讀了官方的facebook文檔,我不明白我需要什麼。我猶豫不決,如果我需要使用Graph API或的社交插件

Login-Button能否請你幫我解決我的疑惑? 非常感謝!

回答

0

要在Flash中使用此功能,您必須通過一些ExternalInterface調用使用JavaScript sdk。這是我總是這樣做的。

AS3

 public function FBconnect():void { 
      ExternalInterface.addCallback("onLogin", onLogin); 
      ExternalInterface.addCallback("onError", onError); 
      ExternalInterface.call("requestLogin"); 
     } 

     private function onError():void { 
      dispatchEvent(new DataEvent(DataEvent.ERROR)); 
     } 

     public function logout():void { 
      ExternalInterface.call("FB.logout", null); 
     } 

     private function onLogin():void { 
      debugTools.trace("FB LOGIN"); 
      connectUser(); 
     } 

     private function connectUser():void { 
      ExternalInterface.addCallback("loadUser", userCallback); 
      ExternalInterface.call("connectUser"); 
     } 

     private function userCallback(data:Array):void { 
      debugTools.trace("FB USER LOADED"); 
      var userData:Object = data[0]; 

      _FBuser = new FBUser(userData.id); 
      _FBuser.firstName = userData.first_name; 
      _FBuser.lastName = userData.last_name; 
      _FBuser.email = userData.email; 

      dispatchEvent(new DataEvent(DataEvent.SUCCESS)); 
     } 

JS

window.fbAsyncInit = function() { 
       FB.init({ 
        appId: YOUR_APP_ID, 
        status: false, 
        cookie: true, 
        xfbml: false 
       });   
      }; 
      (function() { 
       var e = document.createElement('script'); e.async = true; 
       e.src = document.location.protocol + 
       '//connect.facebook.net/en_US/all.js'; 
       document.getElementById('fb-root').appendChild(e); 
      }()); 

      function connectUser() { 
       FB.api('/me', function(response) { 
        if(response) {     
         var usrs = new Array(); 
         usrs.push(response); 
         document.getElementById('flashObj').loadUser(usrs); 
        } else { 
         document.getElementById('flashObj').onError(); 
        } 
       }); 
      }; 

      function requestLogin() { 
       FB.login(function(response) { 
        if (response.authResponse) { 
         document.getElementById('flashObj').onLogin();    
        } else { 
         document.getElementById('flashObj').onError(); 
        } 
       }, {scope:'email'}); 
      } 

因此,要打破它。

我們在我們的網頁中加載javascript sdk,如果您不知道,請在facebook上查看如何操作的文檔。

接下來,通過ExternalInterface,我們在JS中調用FB.login,並在響應中通過document.getElementById(訪問您的swf)調用AS3函數。

然後我們做同樣的事情來使用Graph API來獲取我們用戶的信息。

根據我的經驗,這是Facebook將用戶連接到Flash應用程序的最佳工作流程。

+0

呃,謝謝..那麼你的理事會是要創建一個應用,不要使用社交插件吧? 那麼這種方法呢? http://permadi.com/blog/2011/02/using-facebook-graph-api-in-flash-as3-1-5/comment-page-1/#comment-1752 它與你很相似,但使用官方FB Api – Sonia

+0

這不是相似的,因爲它使用了非官方的API。 Facebook沒有as3 api(至少現在不存在)。該API可能有效,但我認爲它不再被積極開發,並且由於Facebook API發生了很大變化,所以最好的辦法就是堅持這種做法,但隨時可以使用任何適合您的方法;) – ThomasM

+0

然後您可以在Flash應用中不使用社交插件,因爲社交插件僅適用於html/css/js。你不能在Flash應用程序中使用它們。你可以在swf之外使用它們,然後將數據傳輸到你的swf,但這不是最佳的。 – ThomasM