Policy file error while loading images form facebook

狂风中的少年 提交于 2020-01-02 07:22:26

问题


I making a game leaderboard on facebook. I'm not using connect but working inside the canvas. When I try to load the images from facebook it gives me the following error.

SecurityError: Error #2122: Security sandbox violation: Loader.content: http://test cannot access http://profile.ak.fbcdn.net/v22941/254/15/q652310588_2173.jpg A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.

Here is my loader code

    public var preLoader:Loader;
    preLoader=new Loader();
        **update**
        Security.loadPolicyFile('http://api.facebook.com/crossdomain.xml');
        Security.allowDomain('http://profile.ak.fbcdn.net');
        Security.allowInsecureDomain('http://profile.ak.fbcdn.net');
                    **update-end**


        public function imageContainer(Imagewidth:Number,Imageheight:Number,url:String,path:String) {
        preLoader=new Loader();

        Security.loadPolicyFile("http://api.facebook.com/crossdomain.xml");
        var context:LoaderContext = new LoaderContext();
        context.checkPolicyFile = true;
        context.applicationDomain = ApplicationDomain.currentDomain;

        preLoader.load(new URLRequest(path),context);

Any Ideas? I am importing the right class though.

UPDATE: I am loading the images from a different domain say , calling func http://fahim.com images are from http://profile.ak.fbcdn.net/v22941/254/15/q652310588_2173.jpg something ( I have made sure the pictures are static do not require a facebook login or anything , they are just user public profile pictures)


回答1:


This is the url to the image policy file:

Security.loadPolicyFile('https://fbcdn-profile-a.akamaihd.net/crossdomain.xml');

With this line everything should work just fine.




回答2:


var loaderContext:LoaderContext;
loaderContext= new LoaderContext();
loaderContext.securityDomain=SecurityDomain.currentDomain;
loaderContext.checkPolicyFile = true;

..then pass loaderContext when calling load()




回答3:


got it working, the facebook policy file for images is somewhere else and I turned everything else to "*"

Thanks for the help everyone.

Security.loadPolicyFile('https://fbcdn-profile-a.akamaihd.net/crossdomain.xml');




回答4:


If you just want to display any image, without getting its data a good workaround is not trying to use this data. In that case, you don't need the allow security and cross domain file stuff. Use only a simple loading code:

backgroundLoader.unload();
backgroundLoader.contentLoaderInfo.addEventListener(Event.INIT,backgroundImageLoaded, false, 0, true);

var lc : LoaderContext = new LoaderContext();
lc.checkPolicyFile = false;
backgroundLoader.load(new URLRequest(imagePath_),lc);

where backgroundLoader is a class variable of type Loader. Then when it comes to using the image to add it to your canvas, do not request the data (do not use e.currentTarget.content), only display the image:

function backgroundImageLoaded(e:Event) : void {
   myMovieClip.addChild(backgroundLoader);
}

(Solution from http://www.onegiantmedia.com/as3--load-a-remote-image-from-any-url--domain-with-no-stupid-security-sandbox-errors)



来源:https://stackoverflow.com/questions/2112823/policy-file-error-while-loading-images-form-facebook

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!