是否有可靠的方法来确保为所有 Facebook 图像服务器检索跨域策略文件?

发布于 2024-09-14 01:26:22 字数 868 浏览 3 评论 0原文

我最近开始组装 Facebook Connect AS3 应用程序并通过 Graph API 检索对象和图像。

在本地以外的任何地方运行,我收到以下形式的安全错误:
SecurityError:错误 #2122:安全沙箱违规:Loader.content:xxxx 无法访问 http:/ /photos-a.ak.fbcdn.net/xxxx.jpg 需要策略文件,但加载此媒体时未设置 checkPolicyFile 标志。

如果我添加一行以下形式:
Security.loadPolicyFile("ht_tp://photos-a.ak.fbcdn.net/crossdomain.xml");
-那么我适合该服务器,但似乎有许多具有照片-[字母]格式的域。我已经为字母表中的每一个添加了一个 - 它很高兴成功地检索跨域文件 - 但这似乎不是一个很好的解决方案,并且不适应 Facebook may 将实施的任何新托管设置将来。

我考虑过的一件事是在每个图像的基础上检索跨域策略文件,在发出图像请求之前从图像 URL 捕获域。不幸的是,至少通过 Graph 解决方案(我没有太仔细地研究其他解决方案),他们的服务器在发出请求后解析图像 url,从更通用的东西,如:
ht_tps://graph.facebook.com/[objectId]/picture?type=small&access_token=[accessToken]

有没有人找到更可靠的方法来确保可以在不违反安全沙箱的情况下检索图像?或者 Facebook 是否保留了开发者需要关注的明确列表?

谢谢!

I've recently started putting together a Facebook Connect AS3 app and retrieving objects and images through the Graph API.

Running anywhere but locally, I receive security errors of the form:
SecurityError: Error #2122: Security sandbox violation: Loader.content: xxxx cannot access http://photos-a.ak.fbcdn.net/xxxx.jpg
A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.

If I add a line of the form:
Security.loadPolicyFile("ht_tp://photos-a.ak.fbcdn.net/crossdomain.xml");
-then I'm fine for that server, but it seems that there are any number of domains with the photos-[letter] format. I've added the one for each in the alphabet - which happily retrieves crossdomain files successfully - but it doesn't seem like a nice solution, and doesn't accommodate any new hosting setups Facebook may will implement in the future.

One thing I'd considered was retrieving the crossdomain policy file on a per image basis, capturing the domain from the image URL before making the image request. Unfortunately, at least via the Graph solution (and I haven't looked too closely at the others), their servers resolve the image url after the request is made, from something more generic like:
ht_tps://graph.facebook.com/[objectId]/picture?type=small&access_token=[accessToken]

Has anyone found a more dependable means of ensuring that images can be retrieved without security sandbox violations? Or do Facebook maintain a definitive list that developers need to keep an eye on?

Thanks!

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

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

发布评论

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

评论(2

猫九 2024-09-21 01:26:22

在应用程序的开头加载 facebook 跨域,如下所示;

Security.allowDomain("*");
Security.allowInsecureDomain("*");
Security.loadPolicyFile("http://graph.facebook.com/crossdomain.xml");
Security.loadPolicyFile("https://graph.facebook.com/crossdomain.xml");
Security.loadPolicyFile("http://profile.ak.fbcdn.net/crossdomain.xml");
Security.loadPolicyFile("https://profile.ak.fbcdn.net/crossdomain.xml");
Security.loadPolicyFile("http://profile.cc.fbcdn.net/crossdomain.xml");
Security.loadPolicyFile("https://profile.cc.fbcdn.net/crossdomain.xml");
Security.loadPolicyFile("http://fbcdn-profile-a.akamaihd.net/crossdomain.xml");
Security.loadPolicyFile("https://fbcdn-profile-a.akamaihd.net/crossdomain.xml");
Security.loadPolicyFile("http://fbcdn-sphotos-a.akamaihd.net/crossdomain.xml");
Security.loadPolicyFile("https://fbcdn-sphotos-a.akamaihd.net/crossdomain.xml");

然后每当你想从 facebook 加载图像时,使用 Loader 的 LoaderContext 将 checkPolicy 标志设置为 true ,如下所示;

var context:LoaderContext = new LoaderContext();
context.applicationDomain = ApplicationDomain.currentDomain;
context.checkPolicyFile = true;

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadFacebookPhoto);
loader.load(new URLRequest(YOUR_FACEBOOK_PHOTO_URL),context);

private function onLoadFacebookPhoto(e:Event):void
{
    addChild(Bitmap(LoaderInfo(e.target).content));
}

Load the facebook crossdomains on the initial of your application as below;

Security.allowDomain("*");
Security.allowInsecureDomain("*");
Security.loadPolicyFile("http://graph.facebook.com/crossdomain.xml");
Security.loadPolicyFile("https://graph.facebook.com/crossdomain.xml");
Security.loadPolicyFile("http://profile.ak.fbcdn.net/crossdomain.xml");
Security.loadPolicyFile("https://profile.ak.fbcdn.net/crossdomain.xml");
Security.loadPolicyFile("http://profile.cc.fbcdn.net/crossdomain.xml");
Security.loadPolicyFile("https://profile.cc.fbcdn.net/crossdomain.xml");
Security.loadPolicyFile("http://fbcdn-profile-a.akamaihd.net/crossdomain.xml");
Security.loadPolicyFile("https://fbcdn-profile-a.akamaihd.net/crossdomain.xml");
Security.loadPolicyFile("http://fbcdn-sphotos-a.akamaihd.net/crossdomain.xml");
Security.loadPolicyFile("https://fbcdn-sphotos-a.akamaihd.net/crossdomain.xml");

and then whenever you want to load an image from facebook, set the checkPolicy flag to true using the Loader's LoaderContext as below;

var context:LoaderContext = new LoaderContext();
context.applicationDomain = ApplicationDomain.currentDomain;
context.checkPolicyFile = true;

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadFacebookPhoto);
loader.load(new URLRequest(YOUR_FACEBOOK_PHOTO_URL),context);

private function onLoadFacebookPhoto(e:Event):void
{
    addChild(Bitmap(LoaderInfo(e.target).content));
}
放低过去 2024-09-21 01:26:22

理想情况下,我猜测您希望 Flash 自行获取策略文件,而不是使用 Security.loadPolicyFile 触发它。您是否尝试过简单地为 Loader 的 LoaderContext 设置 checkPolicyFile 标志?

另外,我相信当您使用 URLLoader 而不是 Loader 时,Flash 会自动请求策略文件,因此您也可以尝试一下。棘手的是,如果您使用 Loader,即使没有跨域策略,Flash 也会让您显示已加载的内容,因此除非您告诉它,否则它不会加载。当您使用 URLLoader 时,除非存在策略文件,否则不允许加载本身,因此 Flash 会自动获取它。

Ideally I would guess that you'd want Flash to get the policy file on its own, rather than triggering it with Security.loadPolicyFile. Have you tried simply setting the checkPolicyFile flag for your Loader's LoaderContext?

Alternately, I believe that when you use URLLoader instead of Loader, Flash will request a policy file automatically, so you could try that as well. The tricky thing is that if you use Loader, Flash will let you display what you've loaded even without a crossdomain policy, so it doesn't load one unless you tell it to. When you use URLLoader, the load itself is not allowed unless there's a policy file, so Flash gets it automatically.

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