daogr / facebook-actionscript-api

Automatically exported from code.google.com/p/facebook-actionscript-api
0 stars 0 forks source link

Facebook.init(APP_ID, onInit) #294

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
//---------------------------------------------------------------------
// What steps will reproduce the problem?
//---------------------------------------------------------------------

1.  Graph API 1.6 Examples (FlashWebExample)
2.  Edit FlashWebMain.as, "APP_ID", line 42
3.  Upload FlashWebExample.swf and index.php
4.  Load url:
    http://apps.facebook.com/asthreetest/
    http://belshi.com/as3test/

//---------------------------------------------------------------------
// What is the expected output? What do you see instead?
//---------------------------------------------------------------------

A. On Facebook:
1.  if user logged in and first time in app show "perms" and "user info"
1.  if user logged in and second time in app show "user info"

B. On website:
1.  if user logged in and first time in app show "perms" and "user info"
2.  if user logged in and second time in app show "user info"
3.  if user logged out show "login" (and 1 or 2)

//---------------------------------------------------------------------
// What version of the product are you using? On what operating system?
//---------------------------------------------------------------------

Adobe Flash CS5

Graph API 1.6 Examples (FlashWebExample)

Chrome 10.0.648.204
Firefox 3.6.16
IE 8.0.7600
Safari 5.0.5
Opera 11.10

Windows 7 Ultimate

//---------------------------------------------------------------------
// Please provide any additional information below.
//---------------------------------------------------------------------

It seams that Facebook.init(APP_ID, onInit) is never called.

I've been searching related issues like "Issue 165" and found no practical 
solution...

This solution:
http://www.pastrytech.com/willy/FacebookActionScript3SDKExample.html
is has same as in the FlashWebExample, except the index.php that its a 
index.html and doesn't have this bit o code "?<? echo(time()) ?>" afetr the 
file.swf

Original issue reported on code.google.com by joaobel...@gmail.com on 23 Apr 2011 at 6:22

GoogleCodeExporter commented 8 years ago
if user is logged in and has already allowed permissions Facebook.init runs 
fine.

if permissions were never allowed Facebook.init doesn't run.

Original comment by joaobel...@gmail.com on 25 Apr 2011 at 5:18

GoogleCodeExporter commented 8 years ago
I'm using Graph API 1.6.

if user is logged in and has already allowed permissions Facebook.init runs 
fine.
if permissions were never allowed Facebook.init doesn’t run.

I think that my index.php is ok, else Facebook.init would never run and it does 
when permissions were previously allowed.

//---------------------------------------------------------------------
// actionscript.as
//---------------------------------------------------------------------

Facebook.init("APP_ID", onInit);

private function onInit(result:Object, fail:Object):void
{
    if (result)
    {
        trace("SUCCESS");
    }
    else
    {
        trace("FAIL");
    }
}

(this actually works when the user has a session opened and had permitted the 
app)

//---------------------------------------------------------------------
// index.php
//---------------------------------------------------------------------
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:fb="http://www.facebook.com/2008/fbml">
<head>      
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"</script>
    <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
</head>

<body>
    <div id="fb-root"></div>

    <div id="flashContent"></div>

    <script type="text/javascript">

        swfobject.embedSWF("FlashWebExample.swf?<? echo(time()) ?>", "flashContent", "650", "700", "9.0", null, null, null, {name:"flashContent"});     

    </script>

</body>

</html>

What's wrong?

Original comment by joaobel...@gmail.com on 25 Apr 2011 at 5:59

GoogleCodeExporter commented 8 years ago
Are you able to get a response when using just the Facebook Javascript SDK? 

http://developers.facebook.com/docs/reference/javascript/FB.init/
http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

<script>
  FB.init({appId: 'YOUR_APP_ID'} );
  FB.getLoginStatus( 
     function( response ) {
        if( response.session ) {
           alert('status session:' + response.session);                         
        } else {
           alert('status no session');                          
        }
     } 
  );
</script>

The API makes a call to FB.getLoginStatus() during init(), which should cause 
it to run the init callback.

Original comment by edwar...@gmail.com on 25 Apr 2011 at 10:48

GoogleCodeExporter commented 8 years ago
No I don't get a response.

I'm attaching a php.

Original comment by joaobel...@gmail.com on 26 Apr 2011 at 3:02

GoogleCodeExporter commented 8 years ago
I've bee searching testing and trying to learn about this subject...

I figured that Facebook.init is running and either returning NULL or a USERID 
depending on login status and permissions.

So I have a new question:
When Facebook.init returns null should I run Facebook.login or should I present 
the user with an option to login? What is the best practice?

Do you have any documentation about best practices on this subject?

Original comment by joaobel...@gmail.com on 27 Apr 2011 at 9:14

GoogleCodeExporter commented 8 years ago
When Facebook.init() returns null, it just simply means you're not currently 
logged in. Although you can call Facebook.login() at this point, you may run 
into an issue with your browser blocking the login popup. This is because the 
popup was not initiated through an user interaction, so its usually better to 
present the user with an option to login.

Original comment by edwar...@gmail.com on 6 May 2011 at 4:07

GoogleCodeExporter commented 8 years ago
Here is my dirty hack of a solution which worked perfectly:

public class FacebookConnect
    {
        public static var isConnected:Boolean = false;
        public static var connecting:Boolean = false;
        private var initDone:Function;
        private var perms:Object;
        private var tm:uint;
        private var appID:String

        public function FacebookConnect( _appID:String, _perms:Object, _initDone:Function )
        {
            perms = _perms;
            initDone = _initDone;
            appID = _appID;

            init( );
        }

        private function init( ):void
        {
            connecting = true;

            Facebook.init( appID );

            if( Facebook.getSession( ) == null)
            {
                freshLogin( );

                checkForSession( );
            }else{

                loginDone( );
            }
        }

        private function checkForSession( ):void
        {
            var fs:* = Facebook.getSession( ).uid;

            Logger.log("FacebookConnect.checkForSession.uid."+fs);

            if( null != fs)
            {
                loginDone( );
                return;
            }else{
                setTimeout( checkForSession, 1000);
            }
        }

        private function loginDone( ):void
        {
            Facebook.init( 
                appID, 
                initComplete,
                {
                    channelURL : 'http://mjdev.rtedge.ca/mpbj/channel.html'
                }
            );
        }

        private function freshLogin( ):void
        {
            Logger.log("FacebookConnect.freshLogin");

            login( );
        }

        private function login( ):void
        {
            perms['channelURL'] = 'http://mjdev.rtedge.ca/mpbj/channel.html';

            Facebook.login
            ( 
                null,
                perms
            );
        }

        private function initComplete(s:Object,f:Object):void
        {
            Logger.log("FacebookConnect._initDoneInternal."+s+":"+f);

            FacebookConnect.isConnected = s != null;

            if( s != null ) initDone( s , f );

            Logger.log( "FacebookConnect."+FacebookConnect.isConnected+":"+JSON.encode(s)+":"+JSON.encode(f) );
        }
    }

Original comment by marcin.a...@gmail.com on 28 Jun 2011 at 7:47

GoogleCodeExporter commented 8 years ago
For a complete workaround to the Facebook.init() problem see this post:
http://blog.flexwiz.net/facebook-as3-api-blues/

Original comment by amos...@gmail.com on 5 Jul 2011 at 10:26

GoogleCodeExporter commented 8 years ago

Original comment by edwar...@gmail.com on 13 Oct 2011 at 7:56