SWF 为 null Facebook Graph API 和 Actionscript 3 库

发布于 2024-10-17 04:23:27 字数 4875 浏览 2 评论 0原文

使用 Facebook Adob​​e Actionscript 3 1.5 Graph API 调用 Facebook.login(handleLogin, {perms:"user_photos,publish_stream"}) 时,我在 Firebug 控制台中收到“swf is null”。不确定问题是什么,但这是 AS3 代码:

  package alvincrespo
  {
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.external.ExternalInterface;
    import flash.text.TextField;
    import fl.controls.Button;
    import flash.utils.Timer;
    import flash.events.TimerEvent;

    //-----------------------
    //Facebook Classes
    import com.facebook.graph.Facebook;
    import com.facebook.graph.data.FacebookSession;
    import com.facebook.graph.net.FacebookRequest;
    //-----------------------

    public class Main extends MovieClip
    {

      public var btn_login              :Button;
      public var txt_status             :TextField;
      private var APP_ID                :String = ""; //put in the app id here


      public function Main():void
      {
        trace("Main");
        btn_login.addEventListener(MouseEvent.CLICK, handleLoginClick);
        Facebook.init(APP_ID, handleInit);
      }

      private function handleInit(response:Object, fail:Object):void
      {
        trace("Main :: handleInit");
        if(response)
        {
          changeToLoginState();
        }
        else
        {
          trace("Main :: handleInit : Did not Init!")        
        }
      }

      private function handleLogin(response:Object, fail:Object):void
      {
        trace("Main :: handleLogin");
        if(response)
        {
          changeToLoginState();        
        }
        else
        {
          trace("Main :: handleLogin : Did not Log In!")
        }
      }

      private function handleLogout(success:Boolean):void 
      {
        trace("Main :: handleLogout");
        btn_login.label = 'Login';
        txt_status.text = "Logged Out";
      }

      private function handleLoginClick(evt:MouseEvent):void
      {
        trace("Main :: handleLoginClick");
        if(Facebook.getSession() == null || Facebook.getSession().accessToken == null)
        {
          trace("Main :: handleLoginClick : if");
          var fbLoginTimer:Timer = new Timer(1000, 1);
              fbLoginTimer.addEventListener(TimerEvent.TIMER_COMPLETE, doFBLoginTimerComplete);
              fbLoginTimer.start();
        } 
        else 
        {
          trace("Main :: handleLoginClick : else");
          Facebook.logout(handleLogout);
        }
      }

      private function changeToLoginState():void 
      {
        trace("Main :: changeToLoginState");
        btn_login.label = 'Logout';
        txt_status.text = "Logged In";
      }

      private function handleSessionChanged(success:Object, fail:Object):void 
      {
        trace("Main :: handleSessionChanged");
        changeToLoginState();
      }    

      private function doFBLoginTimerComplete(evt:TimerEvent):void
      {
        trace("Main :: doFBLoginTimerComplete");
        evt.target.stop();
        Facebook.login(handleLogin, {perms:"user_photos, publish_stream"});
        /*Facebook.callJS('redirect', {perms:"user_photos, publish_stream"});*/
      }
    }
  }

这是 HTML

    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>Page Title</title>
        <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
    </head>
      <body>
        <div id="FlashDiv">
          <h1>You need at least Flash Player 9.0 to view this page.</h1>
          <p>
            <a href="http://www.adobe.com/go/getflashplayer">
              <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
            </a>
          </p>
        </div>
        <script type="text/javascript">
          function redirect() 
          {
            alert("redirect");
           var params = window.location.toString().slice(window.location.toString().indexOf('?'));
           top.location = 'https://graph.facebook.com/oauth/authorize?client_id=&scope=email,publish_stream,offline_access,read_stream&redirect_uri=http://apps.facebook.com/someapp' + params;
          }

            $(document).ready(function(){
                swfobject.embedSWF("main.swf", "FlashDiv", "550", "400", "10");
            });
        </script>
      </body>
    </html>

真的不确定问题是什么。任何帮助,都会很棒!谢谢!

I am getting a 'swf is null' in the Firebug console when calling Facebook.login(handleLogin, {perms:"user_photos, publish_stream"}) using the Facebook Adobe Actionscript 3 1.5 Graph API. Not sure what the issue is, but here is the AS3 Code:

  package alvincrespo
  {
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.external.ExternalInterface;
    import flash.text.TextField;
    import fl.controls.Button;
    import flash.utils.Timer;
    import flash.events.TimerEvent;

    //-----------------------
    //Facebook Classes
    import com.facebook.graph.Facebook;
    import com.facebook.graph.data.FacebookSession;
    import com.facebook.graph.net.FacebookRequest;
    //-----------------------

    public class Main extends MovieClip
    {

      public var btn_login              :Button;
      public var txt_status             :TextField;
      private var APP_ID                :String = ""; //put in the app id here


      public function Main():void
      {
        trace("Main");
        btn_login.addEventListener(MouseEvent.CLICK, handleLoginClick);
        Facebook.init(APP_ID, handleInit);
      }

      private function handleInit(response:Object, fail:Object):void
      {
        trace("Main :: handleInit");
        if(response)
        {
          changeToLoginState();
        }
        else
        {
          trace("Main :: handleInit : Did not Init!")        
        }
      }

      private function handleLogin(response:Object, fail:Object):void
      {
        trace("Main :: handleLogin");
        if(response)
        {
          changeToLoginState();        
        }
        else
        {
          trace("Main :: handleLogin : Did not Log In!")
        }
      }

      private function handleLogout(success:Boolean):void 
      {
        trace("Main :: handleLogout");
        btn_login.label = 'Login';
        txt_status.text = "Logged Out";
      }

      private function handleLoginClick(evt:MouseEvent):void
      {
        trace("Main :: handleLoginClick");
        if(Facebook.getSession() == null || Facebook.getSession().accessToken == null)
        {
          trace("Main :: handleLoginClick : if");
          var fbLoginTimer:Timer = new Timer(1000, 1);
              fbLoginTimer.addEventListener(TimerEvent.TIMER_COMPLETE, doFBLoginTimerComplete);
              fbLoginTimer.start();
        } 
        else 
        {
          trace("Main :: handleLoginClick : else");
          Facebook.logout(handleLogout);
        }
      }

      private function changeToLoginState():void 
      {
        trace("Main :: changeToLoginState");
        btn_login.label = 'Logout';
        txt_status.text = "Logged In";
      }

      private function handleSessionChanged(success:Object, fail:Object):void 
      {
        trace("Main :: handleSessionChanged");
        changeToLoginState();
      }    

      private function doFBLoginTimerComplete(evt:TimerEvent):void
      {
        trace("Main :: doFBLoginTimerComplete");
        evt.target.stop();
        Facebook.login(handleLogin, {perms:"user_photos, publish_stream"});
        /*Facebook.callJS('redirect', {perms:"user_photos, publish_stream"});*/
      }
    }
  }

And here is the HTML

    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>Page Title</title>
        <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
    </head>
      <body>
        <div id="FlashDiv">
          <h1>You need at least Flash Player 9.0 to view this page.</h1>
          <p>
            <a href="http://www.adobe.com/go/getflashplayer">
              <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
            </a>
          </p>
        </div>
        <script type="text/javascript">
          function redirect() 
          {
            alert("redirect");
           var params = window.location.toString().slice(window.location.toString().indexOf('?'));
           top.location = 'https://graph.facebook.com/oauth/authorize?client_id=&scope=email,publish_stream,offline_access,read_stream&redirect_uri=http://apps.facebook.com/someapp' + params;
          }

            $(document).ready(function(){
                swfobject.embedSWF("main.swf", "FlashDiv", "550", "400", "10");
            });
        </script>
      </body>
    </html>

Really not sure what the issue is. Any help, would be great! Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零度° 2024-10-24 04:23:27

基本上,您需要设置对象标记的名称和 ID,您可以使用 SWFObject 轻松完成此操作,如下所示。您还需要设置适当的allowscriptaccess 属性。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
        <head>
            <title></title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
            <script type="text/javascript">
                var flashvars = {};
                var params = {};
                params.allowscriptaccess = "sameDomain";
                var attributes = {};
                attributes.id = "FlashDiv";
                attributes.name = "FlashDiv";
                swfobject.embedSWF("main.swf", "FlashDiv", "550", "400", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
            </script>
        </head>
        <body>
            <div id="FlashDiv">
                <a href="http://www.adobe.com/go/getflashplayer">
                    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                </a>
            </div>
        </body>
    </html>

Basically, you need to set the name and ID of the object tag, you can do that easily with SWFObject as you can see below. You also need to have the appropriate allowscriptaccess attribute set.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
        <head>
            <title></title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
            <script type="text/javascript">
                var flashvars = {};
                var params = {};
                params.allowscriptaccess = "sameDomain";
                var attributes = {};
                attributes.id = "FlashDiv";
                attributes.name = "FlashDiv";
                swfobject.embedSWF("main.swf", "FlashDiv", "550", "400", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
            </script>
        </head>
        <body>
            <div id="FlashDiv">
                <a href="http://www.adobe.com/go/getflashplayer">
                    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                </a>
            </div>
        </body>
    </html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文