Sandra Willford
Sandra Willford

Reputation: 3789

youtube api json url

I am starting a little jquery plugin for a youtube playlist and I am having problems constructing the URL properly

this is my code:

var playlist = {
    playlist: '**',
    apiKey: '**',
    container: $('#test'),
    shuffle: false
}

function player() {
    var url = 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=$'+playlist.playlist+'&key=$'+playlist.apiKey+'&callback=?';
    console.log(url);
    $.getJSON(url, function(result){
        $.each(result, function(){
            $('#test').append();
        });
    });
}

and this is what the url above returns:

{"error":{"errors":[{"domain":"global","reason":"invalidParameter","message":"Invalid value for parameter callback: ","locationType":"parameter","location":"callback"}],"code":400,"message":"Invalid value for parameter callback: "}}

Upvotes: 0

Views: 424

Answers (2)

A l w a y s S u n n y
A l w a y s S u n n y

Reputation: 38502

Why you putted the callback=? and extra $ before the variables. I just used your credentials and get back the json response data.

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=PLoyiiz-eZk1WRfVo0JR8YyRiYhuJBwkaY&key=#######

N.B: Don't expose your key for public usage.

Upvotes: 2

Manel Alonso
Manel Alonso

Reputation: 397

You need to put on the callback a function to execute. If you don't want anything you can just put false like this &callback=false. On your code it will be like this:

var url = 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=$'+playlist.playlist+'&key=$'+playlist.apiKey+'&callback=false';

Hope it helps you.

Upvotes: 1

Related Questions