我需要开发一个基于Facebook API的非常复杂的Flash站点,如果有一种方法可以在本地开发,而不是必须一直上传它,我将永远感激。
我看到一个帖子提到设置一些东西给本地主机,但他们从来没有具体说明是什么( is it possible to use facebook API locally? )
非常感谢。
发布于 2012-02-01 12:01:54
在这种情况下,封装是您的朋友。当我使用外部/第三方API时,我喜欢为数据创建自己的包装类。假设你只关心'fbID‘和'userName’。创建一个您自己的类,以便在检索到此数据时保存它(带有getter的私有var,以及1个或多个setter)。下面是一些框架代码:
class MyUserClass{
//declare vars here (_fbID, _userName)
public function setData(userID:String, userName:String):void{
//set the values here.
}
//getters here (get fbID, get userName)
}如果你愿意,你可以使用2个setter函数,但关键是你可以用你想要的任何数据来调用它们。当您的整个应用程序从您的类而不是直接从api获取此信息时,您可以脱机工作。在脱机模式下,你可以插入一些兼容的“假”数据来查看它的工作情况。
现在,您需要通过为您对facebook的每个调用创建一个包装器类型来将其提升到一个新的层次。我这样说的意思是,既然你知道从fb得到什么,你可以假装你真的得到了它,并从那里开始。想要一份好友ID列表?制作一个合理的假列表,让你的应用程序使用它。更好的是,生成尽可能多的假脱机用户,并使服务器调用在将假数据返回给事件侦听器之前延迟一段随机的“延迟”时间。这也将有助于针对可能的竞争条件进行测试。
要做到这一点,一种方法是创建并扩展一个类来执行api调用。好好享受吧。
import flash.events.EventDispatcher;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
class MyApiCaller extends EventDispatcher{
//set up vars to hold call result data
protected var _someData:String;
//make sure to declare some event types for the callbacks
public static const SERVERCALL1_COMPLETE:String = "servercall1_complete";
function MyApiCaller(){
//init things....
}
public function doServerCall1(...args:*):void {
//create the ulrLoader etc...
//set up event listener to onServerCall1Complete
}
public function onServerCall1Complete(event:Event):void {
//parse results, save to vars
//fire event to notify the caller
dispatchEvent(new Event(SERVERCALL1_COMPLETE));
}
//getter to be used when the waiting object gets the SERVERCALL1_COMPLETE event
public function get someData():String {return _someData;}
}
class MyFakeApiCaller extends MyApiCaller{
//set up any additional types (random user data etc..) that would not be found in the base class
//no need to redeclare the event types
function MyFakeApiCaller(){
//init things....
}
override public function doServerCall1(...args:*):void {
//wait a random amount of time via Timer, set up event listener to onServerCall1Complete
}
override public function onServerCall1Complete(event:Event):void {
//event is a TimerEvent in this case
//generate data / choose random data
//save to vars: _someData = ...
//fire event to notify the caller
dispatchEvent(new Event(MyApiCaller.SERVERCALL1_COMPLETE));
}
//getter from base class will be used as usual
}发布于 2012-02-01 11:52:42
我相信https://github.com/facebook/php-sdk加上http://www.apachefriends.org/en/xampp.html是你最好的选择。
https://stackoverflow.com/questions/9089571
复制相似问题