Luis Massola
Luis Massola

Reputation: 25

YoutubeData API V3 - Error 400: required parameter - part

I'm trying to fetch data from Youtube API using jQuery and Ajax GET request with the required parameter, including "part". The GET request is ok (code 200), however when I see the data I'm getting an error 400 "required parameter: part". Could anyone give me some tip to overcome this issue? This is part of my jQuery and the result of the ajax request is right below.

$(document).ready(function(){
    console.log('doc ok');

  $('#tag-search').submit(function(){

    var search_term = {
        q: "test"
    };
    search(search_term);

});

});

    function search(search_term) {
        console.log('searching ...');
        console.dir(search_term);

        var search_term = '';
        var desireSearch = $ ('#tag').val();
        var channelName = 'Iron_Maiden';

  $.ajax({
            method: 'GET',
            url: 'https://www.googleapis.com/youtube/v3/channels?', 
            part : 'contentDetails',
            forUsername: channelName,
            key: '(My personal key)',
            dataType: 'jsonp'
    })
  .done(function(results){
            var result = results.data;
            console.log(result);

});

    }

And this is what I got:

jQuery1900617815546458587_1453343296717 (
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Required parameter: part",
"locationType": "parameter",
"location": "part"
}
],
"code": 400,
"message": "Required parameter: part"
}
}
)

Upvotes: 2

Views: 7240

Answers (1)

Ken Sharp
Ken Sharp

Reputation: 1054

You need to use data: {} in the $.ajax request:

$.ajax({
        method: 'GET',
        url: 'https://www.googleapis.com/youtube/v3/channels?',
        data: { 
        part : 'contentDetails',
        forUsername: channelName,
        key: '(My personal key)'
        },
        dataType: 'jsonp'
})

http://api.jquery.com/jquery.ajax/

Upvotes: 7

Related Questions