Flash Builder 4.5,SecurityError:flickr api 的错误 #3207

发布于 2024-11-14 11:16:45 字数 9773 浏览 2 评论 0原文

我构建了这个漂亮的小 天气/时钟应用 作为学习使用 API 和合并了 yahoo 天气 api 和 flickr api。现在它已正常运行,我决定通过 Flash Builder 4.4 ActionScript Mobile 项目将其移植到 playbook 应用程序。我能够将它安装在剧本模拟器上,但是当应用程序启动时,它显示了一个空白阶段。经过几个小时的研究,我确定这是一个运行时错误。

经过几个小时的研究,我发现调用 flickr api 时出现安全错误。调试器报告以下错误:

安全错误:错误#3207:应用程序沙箱内容无法访问此功能。 在 flash.system::Security$/allowDomain() 在 global$init()[C:\Users\poorpaddy\Adobe Flash Builder 4.5\Scripts\flickrGrabber.as:43] 在天气/addGrabberEvents()[C:\Users\poorpaddy\Adobe Flash Builder 4.5\Weather\src\Weather.as:36] 在Weather()[C:\Users\poorpaddy\Adobe Flash Builder 4.5\Weather\src\Weather.as:22]

我尝试了几个

Security.allowDomain(FLICKR_URL);
Security.loadPolicyFile(CROSSDOMAIN_URL);

没有任何运气的例子。这是我的 flickrGrabber 类。

    package {
    import flash.display.Bitmap;
    import flash.events.ErrorEvent;
    import flash.events.EventDispatcher;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.events.ErrorEvent;
    import flash.events.IOErrorEvent;
    import com.adobe.webapis.flickr.events.FlickrResultEvent;
    import com.adobe.webapis.flickr.*;
    import flash.net.URLRequest;
    import flash.system.Security;
    import flash.system.LoaderContext;
    //

    public class flickrGrabber extends EventDispatcher {
        private const FLICKR_URL:String = "flickr.com";
        private const CROSSDOMAIN_URL:String = "http://api.flickr.com/crossdomain.xml";
        private var imageLoader:Loader
        //
        private var fs:FlickrService;
        private var activeUser:User;
        private var photoList:PagedPhotoList
        private var constrainWidth:Number;
        private var constainHeight:Number;
        private var photoPosition:Number = 0;
        private var flickrSource:String;
        private var searchType:String;
        private var doUserSearch:Boolean;
        private var userData:User;
        private var activePhoto:Photo;
        private var otherDataRecieved:Boolean;

        public function flickrGrabber(parentWidth:Number, parentHeight:Number, api:String, secret:String, flickrSearchTerm:String, searchByUser:Boolean = false) {
            constrainWidth = parentWidth;
            constainHeight = parentHeight;
            flickrSource = flickrSearchTerm
            doUserSearch = searchByUser;
            //
            imageLoader = new Loader();
            imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageReady);
            imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onImageError);
            //
            Security.allowDomain(FLICKR_URL);
            Security.loadPolicyFile(CROSSDOMAIN_URL);
            //
            fs = new FlickrService(api);
            //  
            fs.addEventListener(FlickrResultEvent.AUTH_GET_FROB, hGetFrob);
            fs.addEventListener(FlickrResultEvent.PHOTOS_GET_SIZES, recievePhotoSize);
            fs.addEventListener(FlickrResultEvent.PEOPLE_GET_INFO, recieveUserInfo);
            fs.addEventListener(FlickrResultEvent.PEOPLE_FIND_BY_USERNAME, userSearchResults);
            fs.addEventListener(FlickrResultEvent.PEOPLE_GET_PUBLIC_PHOTOS, recievePhotoList);          
            fs.addEventListener(FlickrResultEvent.PHOTOS_SEARCH , recievePhotoList);
            //
            fs.secret = secret;
            //
            fs.auth.getFrob();
        }
        private function hGetFrob(evt:FlickrResultEvent):void {
            if (evt.success) {
                if (doUserSearch){
                    fs.people.findByUsername(flickrSource);
                }else {
                    fs.photos.search("", flickrSource, "any", "", null, null, null, null, -1, "", 100, 1, "interestingness-desc");
                }
            } else {
                reportError("Error obtaining Frob from flickr");
            }
        }
        private function userSearchResults(evt:FlickrResultEvent):void {
            if (evt.success) {
                activeUser = evt.data.user;
                fs.people.getPublicPhotos(activeUser.nsid);
            } else {
                reportError("Count not find specified user name");
            }
        }       
        private function recievePhotoList(evt:FlickrResultEvent):void {
            photoList = evt.data.photos as PagedPhotoList;
            if (photoList.total > 0){
                dispatchEvent(new Event("flickrConnectionReady", false));
            } else {
                reportError("No results recieved for user/search");
            }
        }
        public function loadNextImage():void {
            activePhoto = photoList.photos[photoPosition]; 
            otherDataRecieved = false;
            fs.people.getInfo(activePhoto.ownerId);
            fs.photos.getSizes(activePhoto.id);
            //
            if (photoPosition+1 > photoList.photos.length-1) {
                photoPosition = 0;
            } else {
                photoPosition ++
            }
        }
        private function recieveUserInfo(evt:FlickrResultEvent):void {
            userData = evt.data.user as User;
            checkReadyStatus();
        }
        private function recievePhotoSize(evt:FlickrResultEvent):void {
            if (evt.success){
                var sizeArr:Array = evt.data.photoSizes;
                var sizeObject:PhotoSize = sizeArr[i];
                //Pull the photo that is closest to the target size.
                for (var i:int = 0; i < sizeArr.length; i++) {
                    sizeObject = sizeArr[i];    
                    if (sizeObject.width > constrainWidth || sizeObject.height > constainHeight) {
                        break;
                    }
                }
                imageLoader.load(new URLRequest(sizeObject.source), new LoaderContext(true));
            } else {
                reportError("Photo sizes were not recieved");
            }
        }
        private function checkReadyStatus():void {
            if (otherDataRecieved) {
                dispatchEvent(new Event("imageReady"));
            } else {
                otherDataRecieved = true;
            }
        }
        //
        private function onImageReady(evt:Event):void {
            try {
                var imageAlias:Bitmap = imageLoader.content as Bitmap;
            } catch (e:Error) {
                reportError("Returned image was not a proper bitmap: " + imageLoader.loaderInfo.url);
            }
            checkReadyStatus();
        }
        private function onImageError(evt:IOErrorEvent):void {
            reportError("Error loading image: " + imageLoader.loaderInfo.url);
        }
        public function get image():Bitmap {
            return imageLoader.content as Bitmap;
        }
        public function get imageTitle():String {
            return activePhoto.title;
        }
        public function get imageAuthor():String {
            return userData.fullname;
        }
        private function reportError(errorString:String):void {
            dispatchEvent(new ErrorEvent("flickrGrabberError", false, false, errorString));
        }
    }
}

这是我的 DocumentClass / Weather.as 引用 flickerGRabber 类。

    package
{
    import flash.display.MovieClip;
    import flickrGrabber;
    import flash.events.*;

    public class Weather extends MovieClip
    {

        private var apiKey:String = "###removed for this posting###";
        private var apiSecret:String = "###removed for this posting###";
        public var flickrLocationName:String = "San Diego";
        private var grabber:flickrGrabber;
        private var la:LoadAnimation = new LoadAnimation;
        public var backgroundClip:MovieClip;
        private var clock:ClockObject = new ClockObject;
        public var foreCast:WeatherObject = new WeatherObject;
        private var settingsPanel:KeyboardObject = new KeyboardObject;

        public function Weather()
        {
            addGrabberEvents();
            clock.x = 492;
            clock.y = 375;
            addChild(clock);
            foreCast.x = 27;
            foreCast.y = 12;
            addChild(foreCast);
            settingsPanel.x = 38;
            settingsPanel.y = 28;
            addChild(settingsPanel);
        }

        public function addGrabberEvents():void
        {
            grabber = new flickrGrabber(1024,600,apiKey,apiSecret,flickrLocationName,false);
            grabber.addEventListener("imageReady", onLoadedImage);
            grabber.addEventListener("flickrGrabberError", onErrorImage);
            grabber.addEventListener("flickrConnectionReady", onFlickrReady);
        }
        public function onFlickrReady(evt:Event):void
        {
            la.x = stage.stageWidth - (la.width + 20);
            la.y = 20;
            addChild(la);
            grabber.loadNextImage();
        }
        public function onLoadedImage(evt:Event):void
        {
            backgroundClip = new MovieClip();
            addChildAt(backgroundClip,0);
            backgroundClip.addChild(grabber.image);
            removeChild(la);
        }
        public function removeMe(e:MouseEvent):void
        {
            removeChild(backgroundClip);
            addGrabberEvents();
            settingsPanel.closeKeyboard(null);
            settingsPanel.keyBoardPanel.statusMessage.msg_txt.text = ""
            settingsPanel.keyBoardPanel.zipCodeEntry.zipCodeTxt.text = ""
        }

        public function onErrorImage(evt:ErrorEvent):void
        {
            trace("Report error: " + evt.text);
        }

    }
}

非常感谢您的帮助,我已经被困了几天了。

I built this nifty little weather/clock app as a way of learning to work with API's and incorporates both the yahoo weather api and the flickr api. Now that it is in functioning order, I decided I would port it over to a playbook app via a Flash Builder 4.4 ActionScript Mobile project. I was able to get it installed on the playbook simulator just fine however when the app launched it showed a blank stage. After several hours of research I determined it was a runtime error.

After several more hours of research I found it was a security error when making a call out to the flickr api. The debugger reports the following error:

SecurityError: Error #3207: Application-sandbox content cannot access this feature.
at flash.system::Security$/allowDomain()
at global$init()[C:\Users\poorpaddy\Adobe Flash Builder 4.5\Scripts\flickrGrabber.as:43]
at Weather/addGrabberEvents()[C:\Users\poorpaddy\Adobe Flash Builder 4.5\Weather\src\Weather.as:36]
at Weather()[C:\Users\poorpaddy\Adobe Flash Builder 4.5\Weather\src\Weather.as:22]

I have tried several examples of

Security.allowDomain(FLICKR_URL);
Security.loadPolicyFile(CROSSDOMAIN_URL);

Without any luck. Here is my flickrGrabber class.

    package {
    import flash.display.Bitmap;
    import flash.events.ErrorEvent;
    import flash.events.EventDispatcher;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.events.ErrorEvent;
    import flash.events.IOErrorEvent;
    import com.adobe.webapis.flickr.events.FlickrResultEvent;
    import com.adobe.webapis.flickr.*;
    import flash.net.URLRequest;
    import flash.system.Security;
    import flash.system.LoaderContext;
    //

    public class flickrGrabber extends EventDispatcher {
        private const FLICKR_URL:String = "flickr.com";
        private const CROSSDOMAIN_URL:String = "http://api.flickr.com/crossdomain.xml";
        private var imageLoader:Loader
        //
        private var fs:FlickrService;
        private var activeUser:User;
        private var photoList:PagedPhotoList
        private var constrainWidth:Number;
        private var constainHeight:Number;
        private var photoPosition:Number = 0;
        private var flickrSource:String;
        private var searchType:String;
        private var doUserSearch:Boolean;
        private var userData:User;
        private var activePhoto:Photo;
        private var otherDataRecieved:Boolean;

        public function flickrGrabber(parentWidth:Number, parentHeight:Number, api:String, secret:String, flickrSearchTerm:String, searchByUser:Boolean = false) {
            constrainWidth = parentWidth;
            constainHeight = parentHeight;
            flickrSource = flickrSearchTerm
            doUserSearch = searchByUser;
            //
            imageLoader = new Loader();
            imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageReady);
            imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onImageError);
            //
            Security.allowDomain(FLICKR_URL);
            Security.loadPolicyFile(CROSSDOMAIN_URL);
            //
            fs = new FlickrService(api);
            //  
            fs.addEventListener(FlickrResultEvent.AUTH_GET_FROB, hGetFrob);
            fs.addEventListener(FlickrResultEvent.PHOTOS_GET_SIZES, recievePhotoSize);
            fs.addEventListener(FlickrResultEvent.PEOPLE_GET_INFO, recieveUserInfo);
            fs.addEventListener(FlickrResultEvent.PEOPLE_FIND_BY_USERNAME, userSearchResults);
            fs.addEventListener(FlickrResultEvent.PEOPLE_GET_PUBLIC_PHOTOS, recievePhotoList);          
            fs.addEventListener(FlickrResultEvent.PHOTOS_SEARCH , recievePhotoList);
            //
            fs.secret = secret;
            //
            fs.auth.getFrob();
        }
        private function hGetFrob(evt:FlickrResultEvent):void {
            if (evt.success) {
                if (doUserSearch){
                    fs.people.findByUsername(flickrSource);
                }else {
                    fs.photos.search("", flickrSource, "any", "", null, null, null, null, -1, "", 100, 1, "interestingness-desc");
                }
            } else {
                reportError("Error obtaining Frob from flickr");
            }
        }
        private function userSearchResults(evt:FlickrResultEvent):void {
            if (evt.success) {
                activeUser = evt.data.user;
                fs.people.getPublicPhotos(activeUser.nsid);
            } else {
                reportError("Count not find specified user name");
            }
        }       
        private function recievePhotoList(evt:FlickrResultEvent):void {
            photoList = evt.data.photos as PagedPhotoList;
            if (photoList.total > 0){
                dispatchEvent(new Event("flickrConnectionReady", false));
            } else {
                reportError("No results recieved for user/search");
            }
        }
        public function loadNextImage():void {
            activePhoto = photoList.photos[photoPosition]; 
            otherDataRecieved = false;
            fs.people.getInfo(activePhoto.ownerId);
            fs.photos.getSizes(activePhoto.id);
            //
            if (photoPosition+1 > photoList.photos.length-1) {
                photoPosition = 0;
            } else {
                photoPosition ++
            }
        }
        private function recieveUserInfo(evt:FlickrResultEvent):void {
            userData = evt.data.user as User;
            checkReadyStatus();
        }
        private function recievePhotoSize(evt:FlickrResultEvent):void {
            if (evt.success){
                var sizeArr:Array = evt.data.photoSizes;
                var sizeObject:PhotoSize = sizeArr[i];
                //Pull the photo that is closest to the target size.
                for (var i:int = 0; i < sizeArr.length; i++) {
                    sizeObject = sizeArr[i];    
                    if (sizeObject.width > constrainWidth || sizeObject.height > constainHeight) {
                        break;
                    }
                }
                imageLoader.load(new URLRequest(sizeObject.source), new LoaderContext(true));
            } else {
                reportError("Photo sizes were not recieved");
            }
        }
        private function checkReadyStatus():void {
            if (otherDataRecieved) {
                dispatchEvent(new Event("imageReady"));
            } else {
                otherDataRecieved = true;
            }
        }
        //
        private function onImageReady(evt:Event):void {
            try {
                var imageAlias:Bitmap = imageLoader.content as Bitmap;
            } catch (e:Error) {
                reportError("Returned image was not a proper bitmap: " + imageLoader.loaderInfo.url);
            }
            checkReadyStatus();
        }
        private function onImageError(evt:IOErrorEvent):void {
            reportError("Error loading image: " + imageLoader.loaderInfo.url);
        }
        public function get image():Bitmap {
            return imageLoader.content as Bitmap;
        }
        public function get imageTitle():String {
            return activePhoto.title;
        }
        public function get imageAuthor():String {
            return userData.fullname;
        }
        private function reportError(errorString:String):void {
            dispatchEvent(new ErrorEvent("flickrGrabberError", false, false, errorString));
        }
    }
}

And here is my DocumentClass / Weather.as that references the flickerGRabber class.

    package
{
    import flash.display.MovieClip;
    import flickrGrabber;
    import flash.events.*;

    public class Weather extends MovieClip
    {

        private var apiKey:String = "###removed for this posting###";
        private var apiSecret:String = "###removed for this posting###";
        public var flickrLocationName:String = "San Diego";
        private var grabber:flickrGrabber;
        private var la:LoadAnimation = new LoadAnimation;
        public var backgroundClip:MovieClip;
        private var clock:ClockObject = new ClockObject;
        public var foreCast:WeatherObject = new WeatherObject;
        private var settingsPanel:KeyboardObject = new KeyboardObject;

        public function Weather()
        {
            addGrabberEvents();
            clock.x = 492;
            clock.y = 375;
            addChild(clock);
            foreCast.x = 27;
            foreCast.y = 12;
            addChild(foreCast);
            settingsPanel.x = 38;
            settingsPanel.y = 28;
            addChild(settingsPanel);
        }

        public function addGrabberEvents():void
        {
            grabber = new flickrGrabber(1024,600,apiKey,apiSecret,flickrLocationName,false);
            grabber.addEventListener("imageReady", onLoadedImage);
            grabber.addEventListener("flickrGrabberError", onErrorImage);
            grabber.addEventListener("flickrConnectionReady", onFlickrReady);
        }
        public function onFlickrReady(evt:Event):void
        {
            la.x = stage.stageWidth - (la.width + 20);
            la.y = 20;
            addChild(la);
            grabber.loadNextImage();
        }
        public function onLoadedImage(evt:Event):void
        {
            backgroundClip = new MovieClip();
            addChildAt(backgroundClip,0);
            backgroundClip.addChild(grabber.image);
            removeChild(la);
        }
        public function removeMe(e:MouseEvent):void
        {
            removeChild(backgroundClip);
            addGrabberEvents();
            settingsPanel.closeKeyboard(null);
            settingsPanel.keyBoardPanel.statusMessage.msg_txt.text = ""
            settingsPanel.keyBoardPanel.zipCodeEntry.zipCodeTxt.text = ""
        }

        public function onErrorImage(evt:ErrorEvent):void
        {
            trace("Report error: " + evt.text);
        }

    }
}

Your assistance would be very much appreciated I've been stuck for a couple days.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染墨丶若流云 2024-11-21 11:16:45

啊。我花了很多时间尝试重构代码或寻找我遗漏的东西。事实证明我所要做的就是删除这两行。

Security.allowDomain(FLICKR_URL);
Security.loadPolicyFile(CROSSDOMAIN_URL);

Argh. I spent many hours trying to refactor the code or look for something I was missing. It turns out all I have to do was remove the two lines.

Security.allowDomain(FLICKR_URL);
Security.loadPolicyFile(CROSSDOMAIN_URL);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文