开发者

read facebook rss in Flash (cross domain)

I am building an application that fetches the following rss feed and displays it. http://www.facebook.com/feeds/page.php?id=94572408519&format=rss20 It works fine locally but when i uplaod the swf online stops working. I already added a crossdomain policy file and it doesn't help. The odd thing is that Twitter Feed is loading fine (both locally and online) Any ideas? this is my code:

override protected function initContent():void {
        super.initContent();
        Security.allowDomain("https://facebook.com")

        setContent("Loading data...");
        var req:URLRequest = n开发者_高级运维ew URLRequest("https://facebook.com/feeds/page.php?id=94572408519&format=rss20");
        var l:URLLoader = new URLLoader();
        l.addEventListener(Event.COMPLETE, onContentLoad);
        l.addEventListener(IOErrorEvent.IO_ERROR, onContentLoadErr);
        l.load(req);
    }    
private function onContentLoad(event:Event):void {
        var loadedXml:XML = new XML(event.target.data);
        //trace(xml.item);
        loadedXml.ignoreWhitespace=true;
        var len=loadedXml.channel.item.length();
        var content:String = "";
        for (var i:int = 0; i < len; i++) {
            if (loadedXml.channel.item[i].link){ 
                content += "<a href='" + loadedXml.channel.item[i].link + "' target='_blank'>";
                content += loadedXml.channel.item[i].title+"</a>";
                content += "\n\n";

            }
        }
        setContent(content);
    }


The site hosting the web service decides the security restrictions for their service. So Facebook needs a crossdomain.xml in order for any flash running from a website to connect to them.

I built a small class to work-around flash's restrictions by using the browser's javascript. Loading with JSONP has less restrictions than Flash so it is happy to act as a proxy for Flash to load cross-domain services from the client-side.

JSONP.as - http://gist.github.com/1204728

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜