Facebook abobe as3 api for air for mobile [英] Facebook abobe as3 api for air for mobile

查看:43
本文介绍了Facebook abobe as3 api for air for mobile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在规划一个项目,该项目涉及使用 Facebook 登录的跨平台(Android 和 I.O.S)移动应用程序.我没有使用面子书 API 的经验,也找不到任何可供新手使用的完整材料.我想将 air 用于其跨平台功能,因此希望避免针对每个平台使用多种解决方案.我已经做了很多寻求帮助的搜索,但没有找到太多.你们中的任何人都可以向我指出您发现从此类事情开始时完全使用的资源.

I am planing a project that involves a cross platform (Android and I.O.S) mobile app that logs in using Facebook. I have no experience with the face book API and cant find any use full material for newbies. I want to use air for its cross platform capabilities so want to avoid multiple solutions for each platform. I have done many searches for help but haven't found much. Can any of you point me to resources you found use full starting off with this sort of thing.

推荐答案

AS3 Facebook API 就是您所需要的.( http://code.google.com/p/facebook-actionscript-api/ ) 也许您将不得不更改一些内容(例如那里的 JSON 方法),但除此之外它似乎还可以正常工作.您也可以从那里下载几个示例,您可以查看不同类型环境的用法.

The AS3 Facebook API is all you need. ( http://code.google.com/p/facebook-actionscript-api/ ) Maybe you will have to change a few things (like the JSON methods in there) but otherwise it seems to work alright. You can download several examples from there as well, you can see the usage for different types of environment.

另外,阅读 Tom Krcha 的这篇文章http://www.adobe.com/devnet/games/articles/getting-started-with-facebooksdk-actionscript3.html

Also, read this article from Tom Krcha http://www.adobe.com/devnet/games/articles/getting-started-with-facebooksdk-actionscript3.html

如果您有更具体的问题,请提出.这个太笼统了.

If you have more specific questions, ask. This one is too generic.

这是我前段时间为一个小项目写的一个类

Here is a class I wrote some time ago for a small project

package com.company.social {

    import com.facebook.graph.FacebookMobile;
    import com.company.AppConst;
    import com.company.IDestroyable;
    import com.company.Main;
    import com.company.displayassets.WebViewCloseStripe;
    import com.company.events.FacebookControllerEvent;
    import com.company.events.TwitterControllerEvent;

    import flash.display.BitmapData;
    import flash.display.PNGEncoderOptions;
    import flash.display.Sprite;
    import flash.display.Stage;
    import flash.events.EventDispatcher;
    import flash.events.MouseEvent;
    import flash.geom.Rectangle;
    import flash.media.StageWebView;
    import flash.utils.ByteArray;
    import flash.utils.clearTimeout;
    import flash.utils.setTimeout;

    public class FacebookController extends EventDispatcher implements IDestroyable {

        private static const APP_ID:String = "1234512345"; // Your App ID.
        private static const SITE_URL:String = "some_url";
        //Extended permission to access other parts of the user's profile that may be private, or if your application needs to publish content to Facebook on a user's behalf.
        private var _extendedPermissions:Array = ["publish_stream","user_website","user_status","user_about_me"];
        private var _stage:Stage;
        private var _webView:StageWebView;
        private var _topStripe:WebViewCloseStripe;
        private var _activity:String;
        private var _timeoutID:uint;
        public static const ACTIVITY_LOGIN:String = "login";
        public static const ACTIVITY_POST:String = "post";

        public function FacebookController(stage:Stage) {
            _stage = stage;
            init();
        }

        private function init():void {
            _activity = ACTIVITY_LOGIN;
            startTimeout();
            FacebookMobile.init(APP_ID, onHandleInit, null);
        }

        private function onHandleInit(response:Object, fail:Object):void {
            if (response) {
                stopTimeout();
                dispatchEvent(new FacebookControllerEvent(FacebookControllerEvent.LOGIN_COMPLETE));
                //FacebookMobile.api("/me", handleUserInfo);
            }
            else {
                /*trace("no response, login -->");
                for(var prop in fail["error"]) {
                    trace(prop+": "+fail["error"][prop]);
                }*/
                loginUser();
            }
        }

        private function startTimeout():void {
            trace("timeout start");
            clearTimeout(_timeoutID);
            _timeoutID = setTimeout(timeout, AppConst.TIMEOUT_TIME);
        }

        private function timeout():void {
            trace("timed out");
            clearTimeout(_timeoutID);
            dispatchEvent(new FacebookControllerEvent(FacebookControllerEvent.TIMEOUT));
        }

        private function stopTimeout():void {
            trace("timeout stop");
            clearTimeout(_timeoutID);
        }

        private function loginUser():void {
            stopTimeout();
            _topStripe = new WebViewCloseStripe();
            _topStripe.getCloseButton().addEventListener(MouseEvent.CLICK, closeClickHandler);
            _stage.addChild(_topStripe);

            _webView = new StageWebView();
            _webView.viewPort = new Rectangle(0, _topStripe.height, _stage.fullScreenWidth, _stage.fullScreenHeight - _topStripe.height);

            FacebookMobile.login(handleLogin, _stage, _extendedPermissions, _webView);
        }

        private function handleLogin(response:Object, fail:Object):void {
            if(_topStripe) {
                _topStripe.getCloseButton().removeEventListener(MouseEvent.CLICK, closeClickHandler);
                _topStripe.destroy();
                _stage.removeChild(_topStripe);
                _topStripe = null;
            }
            if(_webView) {
                _webView = null;
            }
            if(response) {
                dispatchEvent(new FacebookControllerEvent(FacebookControllerEvent.LOGIN_COMPLETE));
                //FacebookMobile.api('/me', handleUserInfo);
            }
            else {
                dispatchEvent(new FacebookControllerEvent(FacebookControllerEvent.LOGIN_ERROR));
            }
        }

        private function closeClickHandler(e:MouseEvent):void {
            dispatchEvent(new FacebookControllerEvent(FacebookControllerEvent.CLOSE));
        }

        private function handleUserInfo(response:Object, fail:Object):void {
            if (response) {
                for(var prop in response) {
                    trace(prop+": "+response[prop]);
                }
            }
        }

        private function handleUploadImage(result:Object, fail:Object):void {
            stopTimeout();
            if(result) {
                dispatchEvent(new FacebookControllerEvent(FacebookControllerEvent.POST_COMPLETE));
            }
            else {
                dispatchEvent(new FacebookControllerEvent(FacebookControllerEvent.POST_ERROR));
            }
        }

        public function postWithImage(message:String, imageData:BitmapData):void {
            _activity = ACTIVITY_POST;
            var byteArray:ByteArray = imageData.encode(new Rectangle(0, 0, imageData.width, imageData.height), new PNGEncoderOptions()); 
            var params: Object = new Object;
            params.image = byteArray;
            params.fileName = "image.png";
            params.message = message;
            startTimeout();
            FacebookMobile.api("/me/photos", handleUploadImage, params, "POST");
        }

        public function reset():void {
            FacebookMobile.logout(handleReset, SITE_URL);
        }

        public function handleReset(response:Object):void {
            dispatchEvent(new FacebookControllerEvent(FacebookControllerEvent.RESET));
        }

        public function destroy():void {
            if(_webView) {
                _webView.dispose();
                _webView = null;
            }

            if(_topStripe) {
                _topStripe.getCloseButton().removeEventListener(MouseEvent.CLICK, closeClickHandler);
                _topStripe.destroy();
                _stage.removeChild(_topStripe);
                _topStripe = null;
            }

            _stage = null;
        }
    }
}

这篇关于Facebook abobe as3 api for air for mobile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆