2012-04-06 57 views
0

您好,我一直在使用Google Picker API(http://code.google.com/apis/picker/)过期。我有一个可以搜索YouTube电影的工作演示(代码如下)。Google Picker API:过滤YouTube电影

当前版本返回所有视频。我试图过滤结果,因此它只会列出来自youtube.com的搜索结果。 picker API支持这一点。但我不明白API文档。

该文档(http://code.google.com/apis/picker/docs/reference.html)提到'VideoSearchView.YOUTUBE',并将其描述为“适用于VideoSearchView.setSite()方法的字符串常量”。

我不明白如何在下面的代码中实现此过滤器。任何帮助表示赞赏。

<!-- 
Needs work; it should only display YouTube videos. 

http://code.google.com/apis/picker/docs/reference.html 

Change the key parameter for a domain+path specific API key. Get one here: http://code.google.com/apis/loader/signup.html. 
--> 
<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAANAaPTI0Sup-knGFaDbCNHBSXhCTdTCKo5q_OHnpA1qEpBIP8mRTtPnObFFbe_J21oviL78C86yxHUA"></script> 
<script type="text/javascript"> 
    google.load('picker', '1', {'language':'nl'}); 

    function googlePicker() 
    { 
     /* 
     Displays the users own YouTube movies: 
     picker = picker.addView(google.picker.ViewId.YOUTUBE); 

     Displays all videos: 
     picker = picker.addView(google.picker.ViewId.VIDEO_SEARCH); 

     Displays all videos from youtube.com: 
     ??? 

     Example query that returns non-YouTube results: "Mobile Healing Rooms: Following Jesus on Vimeo" 
     */ 

     var picker = new google.picker.PickerBuilder(); 
     picker = picker.addView(google.picker.ViewId.VIDEO_SEARCH); 
     picker = picker.enableFeature(google.picker.Feature.NAV_HIDDEN); 

     picker = picker.setTitle('Selecteer een YouTube video'); 
     picker = picker.setCallback(googlePickerCallback); 
     picker = picker.build(); 
     picker.setVisible(true); 
    } 

    function googlePickerCallback(data) { 
     var youTubeUrl = (data.action == google.picker.Action.PICKED) ? data.docs[0].url : ''; 

     if (youTubeUrl != '') 
     { 
      $('#block_youtube_url').val(youTubeUrl); 
     } 
    } 
</script> 

回答

1

请尝试以下等效:

// Create and render a Picker object for searching YouTube videos. 
function createPicker() { 
    var picker = new google.picker.PickerBuilder(). 
     addView(new google.picker.VideoSearchView(). 
      setSite(google.picker.VideoSearchView.YOUTUBE)). 
     setCallback(pickerCallback). 
     build(); 
    picker.setVisible(true); 
} 

如果通过ViewId添加视图,你没有得到一个机会来调用视图具体方法。这就是为什么一些View派生类被暴露的原因。

+0

非常感谢!很好的解决方案。它甚至为界面添加了一个YouTube徽标:) – 2012-04-20 09:27:40