开发者

Facebook Login using flex4

I am trying to integrate my application with facebook.I followed the official tutorial on adobe http://www.adobe.com/devnet/facebook/articles/flex_fbgraph_pt3.html I get no errors or warnings. But when I run my app,on click upon login the login window does not pop up at all..as in nothing happens...No errors of any sort..

CAn anyone te开发者_开发知识库ll me what s goinf wrong.Kindly point to some working tutorial

Thanks!!


this is a way to connect to Facebook using Graph API. Everything is explained in comment. This is actually the connecting to facebook, no posting to walls or anything. That part can be found below this class.

package com.DAL 
{
    import com.facebook.graph.Facebook;
    import flash.events.Event;
    import com.facebook.graph.data.FacebookSession;
    import flash.events.EventDispatcher;
    import flash.events.MouseEvent;
    import com.fbLoginButton;
    import com.adobe.serialization.json.JSON;

    public class FBConnect extends EventDispatcher
    {
        /******************************************
        *   Variables
        ******************************************/
        private var _applicationID:String;
        private var _extendedPermissions:Object;

        /******************************************
        *   Constants
        ******************************************/
        public static const CONNECTED:String = "CONNECTED";

        /******************************************
        *   Properties
        ******************************************/             
        public function get ApplicationID():String
        {
            return _applicationID;
        }

        /******************************************
        *   Constructor
        ******************************************/
        public function FBConnect() 
        {
            super();

            //Set applicationid
            _applicationID = "YOUR_ID";

            //Set permissions to ask for
            _extendedPermissions = {perms:"read_stream, publish_stream, user_about_me, read_friendlists, user_photos"};

            //Initialize facebook
            Facebook.init(_applicationID);
        }

        /******************************************
        *   Methods
        ******************************************/     
        public function login(e:MouseEvent):void
        {           
            Facebook.login(handleLogin, _extendedPermissions);
        }

        private function handleLogin(response:Object, fail:Object):void
        {
            dispatchEvent(new Event(CONNECTED));
        }
    }
}

That should take care of connecting to facebook. If you want to post to walls or anything, you can find a small example below.

        /******************************************
        *   Constructor
        ******************************************/
        public function FBLogic() 
        {
            super();

            _connect = new FBConnect();
            _connect.addEventListener(FBConnect.CONNECTED, startLoaders);

            initLoaders();
        }

        /******************************************
        *   Methods
        ******************************************/

        ...

        public function post(message:String):void
        {
            var _params:Object = new Object();

            _params.access_token = Facebook.getSession().accessToken;
            _params.message = message;

            Facebook.api("/" + _userID + "/feed", messagePosted, _params, "POST");
        }

        public function messagePosted(response:Object, fail:Object):void
        {
            dispatchEvent(new Event(MESSAGEPOSTED));
        }

        public function login(e:MouseEvent):void
        {
            var _loginButton:fbLoginButton = e.target as fbLoginButton;
            _loginButton.alpha = 0;
            _loginButton.visible = false;

            _connect.login(e);
        }

If this doesn't do the trick you might have forgotten to add some code to your html file. Be sure to add the following code to the head of your html file:

<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script> 

And you also need a div called fb-root, declared like this.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜