【问题标题】:Google Picker API: filter YouTube moviesGoogle Picker API:过滤 YouTube 电影
【发布时间】:2012-04-06 09:05:48
【问题描述】:

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

当前版本返回所有视频。我正在尝试过滤结果,因此它只会列出来自 youtube.com 的搜索结果。选择器 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>

【问题讨论】:

    标签: youtube google-picker


    【解决方案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 派生类的原因。

    【讨论】:

    • 非常感谢!非常好的解决方案。它甚至在界面上添加了一个 YouTube 徽标 :)
    • 这项工作谢谢,但如果我只想加载我上传的视频怎么办。
    猜你喜欢
    • 1970-01-01
    • 2011-03-25
    • 2012-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-20
    • 2013-09-04
    • 1970-01-01
    相关资源
    最近更新 更多