ReferenceError:错误#1056:无法在com.facebook.graph.Facebook上创建属性com.facebook.graph.core:AbstractFacebook :: oauth2

时间:2015-04-18 09:29:36

标签: javascript android facebook actionscript-3 flash

首先,我想说我一直试图让这个工作超过一年。我尝试了大多数在线提供的教程。我最终复制了一个我在网上找到的模板,但仍然无法让它工作。我有一堆文件,我将发布主要的两个。有人可以告诉我如何修复此错误消息?我不是故意剽窃,如果我可以让这个工作,我可以根据一个工作的例子自己工作。

MainGameFile.as

package {
    import com.adobe.serialization.json.JSON;
    import com.facebook.graph.Facebook;

    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.MouseEvent;
    import flash.net.URLRequest;

    public class FlashMobileWeb extends Sprite {

        protected static const APP_ID:String = "647743112027883"; //Your App Id
        protected static const APP_URL:String = "https://localhost:3000/"; 

        protected var profilePic:Loader;

        public function FlashMobileWeb() {          
            var accessToken:String;
            if (loaderInfo.parameters.accessToken != undefined) {               
                accessToken = String(loaderInfo.parameters.accessToken); //get              
    the token passed in index.php
            }

            Facebook.init(APP_ID, onInit, null, accessToken);           

            loginBtn.addEventListener(MouseEvent.CLICK, handleLoginClick, false,  0, true);
            callBtn.addEventListener(MouseEvent.CLICK, handleCallClick, false, 0, true);

            profilePic = new Loader();
            profilePic.contentLoaderInfo.addEventListener(Event.INIT, handleProfilePicInit, false, 0, true);
            profilePic.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleProfilePicIOError, false, 0, true);
            profileHolder.addChild(profilePic);
        }

        protected function onInit(response:Object, fail:Object):void {
            if (response) {
                outputTxt.appendText("Logged In\n");    
                loginBtn.label = "Logout";
            } else {
                outputTxt.appendText("Click to Login\n");
                loginBtn.label = "Login";
            }
        }

        protected function handleLoginClick(event:MouseEvent):void {            
            if (loginBtn.label == "Login") {
                var redirectUri:String = APP_URL; //Your App URL as specified in facebook.com/developers app settings
                var permissions:Array = ["user_photos", "user_location"];
                Facebook.mobileLogin(redirectUri, "touch", permissions);
            } else {
                outputTxt.appendText("LOGOUT\n");               
                Facebook.mobileLogout(APP_URL); //Redirect user back to your app url                
            }
        }

        protected function onLogout(response:Object):void {
            loginBtn.label = "Login";
            outputTxt.text = "";
        }

        protected function handleCallClick(event:MouseEvent):void {         
            Facebook.api("/me", onApiCall);
        }

        protected function onApiCall(response:Object, fail:Object):void {
            if (response) {                             
                outputTxt.appendText("RESPONSE:\n" + JSON.encode(response) + "\n"); 


                var req:URLRequest = new URLRequest(Facebook.getImageUrl(response.id, "square"));               
                profilePic.load(req);


                profileHolder.nameTxt.text = response.name + "\n";
                if (response.location != null) { profileHolder.nameTxt.appendText(response.location.name); }


            }
        }   

        protected function handleProfilePicInit(event:Event):void {
            profilePic.x = 1;
            profilePic.y = profileHolder.height - profilePic.height >> 1;
        }

        protected function handleProfilePicIOError(event:IOErrorEvent):void {
            outputTxt.appendText("Error Loading Profile Pic\n");
        }
    }
}

AbstractFacebook.as

package com.facebook.graph.core {

    import com.facebook.graph.data.FacebookSession;
    import com.facebook.graph.net.FacebookRequest;

    import flash.net.URLRequestMethod;
    import flash.utils.Dictionary;

    public class AbstractFacebook {

        protected var session:FacebookSession;
        protected var openRequests:Dictionary;

        public function AbstractFacebook():void {
            openRequests = new Dictionary();
        }

        protected function api(method:String,
                                callback:Function = null,
                                params:* = null,
                                requestMethod:String = 'GET'
                                ):void {

      method = (method.indexOf('/') != 0) ?  '/'+method : method;
            if (session != null) {
                if (params == null) { params = {}; }
                params.access_token = session.accessToken;
            }

            var req:FacebookRequest = new FacebookRequest(
                                            FacebookURLDefaults.GRAPH_URL,
                                            requestMethod
                                            );


            openRequests[req] = callback;

            req.call(method, params, handleRequestLoad);

        }

        protected function handleRequestLoad(target:FacebookRequest):void {
            var resultCallback:Function = openRequests[target];
            if (resultCallback === null) {
                delete openRequests[target];
            }

            if (target.success) {
        var data:Object = ('data' in target.data) ? target.data.data : target.data;
                resultCallback(data, null);
            } else {
                resultCallback(null, target.data);
            }

            delete openRequests[target];
        }

        protected function callRestAPI(methodName:String,
                                    callback:Function = null,
                                    values:* = null,
                                    requestMethod:String = 'GET'
                                    ):void {

             if (values == null) { values = {}; }
             values.format = 'json';

            if (session != null) {
                values.access_token = session.accessToken;
            }

            var req:FacebookRequest = new FacebookRequest(
                                                FacebookURLDefaults.API_URL,
                                                requestMethod
                                                );

            openRequests[req] = callback;

            req.call('/method/' + methodName, values, handleRequestLoad);
        }

        protected function fqlQuery(query:String, callback:Function):void {
             callRestAPI('fql.query', callback, {query:query});
        }

        protected function deleteObject(method:String, callback:Function = null):void {
            var params:Object = {method:'delete'};
            api(method, callback, params, URLRequestMethod.POST);
        }

        protected function getImageUrl(id:String, type:String = null):String {
            return FacebookURLDefaults.GRAPH_URL
                            + '/'
                            + id
                            + '/picture'
                            + (type != null?'?type=' + type:'');
        }
    }
}

0 个答案:

没有答案