문제

Hello I've been expirimenting with the Google Picker API (http://code.google.com/apis/picker/). I've got a working demo (code below) that searches for YouTube movies.

This current version returns all videos. I'm trying to filter the results so it'll only list search results from youtube.com. The picker API supports this. But I don't understand the API documentation.

The documentation (http://code.google.com/apis/picker/docs/reference.html) mentions 'VideoSearchView.YOUTUBE' and describes it as "A string constant suitable for the VideoSearchView.setSite() method".

I don't understand how to implement this filter in my code below. Any help is appreciated.

<!--
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>
도움이 되었습니까?

해결책

Try the equivalent of the following:

// 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);
}

If you add views by ViewId, you don't get a chance to call view-specific methods. This is why some View-derived classes are exposed.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top