0

您好,我一直在使用 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>
4

1 回答 1

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 派生类的原因。

于 2012-04-06T15:22:55.373 回答