2010-12-10 75 views
0

我是真的是Adobe Air的新手,我试图通过JavaScript使用YouTube API获取特定用户的YouTube视频列表。无法从Adobe Air访问YouTube API

我试过几个例子,当我只是点击它(在Aptana Studio中)并且作为JavaScript Web应用程序运行时,所有这些例子似乎都很好用。

只要我尝试运行与Adobe Air应用程序相同的东西,我就不会收到任何数据。这是为什么?我不知道是否有什么明显的东西可以忽略或者是什么。

这就是我一直在寻找最近: http://code.google.com/apis/youtube/2.0/developers_guide_json.html

有人能指出我在正确的方向,或告诉我这是为什么Adobe AIR中不工作?

回答

1

更新:好的,这就是我得到了它的工作,任何人从2019参观(帽子的尖端http://xkcd.com/979/):

<?xml version="1.0" encoding="utf-8"?> 
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" 
    backgroundColor="#000000" verticalAlign="middle" horizontalAlign="center" 
    creationComplete="init()" borderStyle="solid"> 

<mx:Script> 
<![CDATA[ 
    import mx.core.UIComponent; 

    public var html : HTMLLoader = null; 
    protected var url : String = null; 


    protected function init() 
    { 
     /* Your embedded html with all the youtube REST calls is in the "local" 
      subdirectory of the application directory. Note the relation between 
      the local url, the sandbox root and the remote url. */ 
     var localUrl : String = "app:/local/yt.html"; 
     var sandboxRoot : String = "http://youtube.com/"; 
     var remoteUrl : String = "http://youtube.com/local/yt.html"; 

     html = new HTMLLoader(); 
     html.addEventListener(Event.COMPLETE, htmlLoaded); 

     /* Embed your youtube html in an iframe that is loaded dynamically. You 
      could also just have this html code in a separate html file and load 
      it through html.load() instead of html.loadString(). */ 
     var htmlString : String = "<html>" 
      + "<body><center>" 
      +"<iframe width='100%' height='100%' src='" +remoteUrl 
       +"' sandboxRoot='"+sandboxRoot+"' documentRoot='app:/' " 
       +" allowCrossDomainXHR='true'" /* May not be necessary */ 
       +" id='yt' name='yt'></iframe>" 
      + "</center></body></html>"; 

     /* The next line is needed to allow the REST API in the embedded html 
      to call home when loading through loadString. */ 
     html.placeLoadStringContentInApplicationSandbox = true; 
     html.loadString(htmlString); 
    } 

    protected function htmlLoaded(e:Event):void 
    { 
     html.removeEventListener(Event.COMPLETE, htmlLoaded); 
     frame.addChild(html); 
     trace("html load complete."); 
    } 
]]> 
</mx:Script> 
<mx:UIComponent id="frame" width="100%" height="100%" visible="true"/> 
</mx:HBox> 

请注意,这是我的代码的清理版本,我没有试过运行它,所以它可能无法正常工作,但实际上它就是这样。