本文介绍了获取 Flex 安全策略的实际 Facebook 和 Twitter 个人资料图像 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试同时显示来自 facebook 和 twitter 的个人资料图片.对于 facebook,我收到的 URL 是这样的(不是实际的 URL):

I'm trying to display the profile images from both facebook and twitter. For facebook, the URLs I'm receiving are something like this (not actual urls):

http://graph.facebook.com/965412145/picture

然后重定向到实际"网址,如下所示:

Which is then redirected to the 'actual' url like this:

http://profile.ak.fbcdn.net/hprofile-ak-snc4/370471_9631690_1796253478_r.jpg

我也在 twitter 上这样做,但有同样的问题(重定向的 url).

I'm also doing this with twitter, with the same issue (redirected url).

所以,当我加载图像时,它加载得很好.但是当我关闭图像所在的容器时,我会收到安全沙箱违规.

So, when I load the image, it loads fine. But when I close the container that the image is in, then I get the security sandbox violation.

如果我像这样从实际"图像 URL 添加 URL,我可以让这一切正常工作:

I can get this all to work if I add the URL from the 'actual' image url like this:

request = new URLRequest("http://profile.ak.fbcdn.net");
loader = new Loader();
context = new LoaderContext();
context.checkPolicyFile = true;
loader.load(request, context);

但是,在运行时,我实际上并不知道实际"图像 url 是什么,因此我无法对该域进行硬编码(我也不想这样做).

However, at run time, I do not actually know what the 'actual' image url is, so I can't hard-code that domain in (nor do I want to).

有没有办法获取图像的实际 url(从 flex 内),以便我可以将正确的域添加到 loadercontext 中?

Is there a way to get the actual url (from within flex) of the image so that I can add the correct domain to the loadercontext?

感谢任何想法!

推荐答案

如果我理解正确,您的问题是您试图从重定向到另一个源的 URL 加载图像.您需要知道重定向的 URL 是什么,以便您可以加载允许操作图像字节的策略文件.

If I understand correctly, your problem is that you're trying to load an image from a URL that redirects to another source. You need to know what the redirected URL is, so you can load a policy file that allow manipulation of image bytes.

如果我理解正确,您需要通过侦听 COMPLETE 事件(或错误事件)来检测重定向的 URL,然后引用 LoaderInfo.url财产.此属性将在发生重定向时反映结束 URL.例如,您将在侦听器中有这样的代码:

If I've understood correctly, you need to detect the redirected URL by listening for the COMPLETE event (or an error event), then reference the LoaderInfo.url property. This property will reflect the end URL in the event of redirects. For example, you would have code like this in the listener:

var ldr:LoaderInfo = event.target as LoaderInfo;
var url:String;
try
{
    url = ldr.url;
    // Split off URL base, load policy file, etc here
}
catch (e:Error)
{
    // Unable to detect final URL due to error.
}

这篇关于获取 Flex 安全策略的实际 Facebook 和 Twitter 个人资料图像 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 04:27