0

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: "}}
1

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.