Consult Youtube API from jquery

2

Is it possible to consume that API from jquery? If I could do it but from PHP, when doing a post like that in jquery:

 $.post("https://www.googleapis.com/youtube/v3/videos?id=VO7wstoK_gI&key=AIzaSyDolRu-zJQdK38G52I_rdxqRqruHx2PSBc&part=snippet,contentDetails,statistics,status",
    function (respuesta) {
    alert(respuesta);
}).fail(function(p) {
    alert(JSON.stringify(p));
});

I do not throw anything, it is clear that I already have the API key and if I could consume it from the backend, I previously consulted a weather API from jquery, so I think it could.

In the alert of the error function I get this:

{"readyState":4,"responseText":"{\n \"error\": {\n  \"errors\": [\n   {\n    \"domain\": \"global\",\n    \"reason\": \"required\",\n    \"message\": \"Login Required\",\n    \"locationType\": \"header\",\n    \"location\": \"Authorization\"\n   }\n  ],\n  \"code\": 401,\n  \"message\": \"Login Required\"\n }\n}\n","responseJSON":{"error":{"errors":[{"domain":"global","reason":"required","message":"Login Required","locationType":"header","location":"Authorization"}],"code":401,"message":"Login Required"}},"status":401,"statusText":"Unauthorized"}
    
asked by Kraken 28.03.2017 в 18:41
source

1 answer

0

You are using $.post , use $.get instead and problem solved:

$.get("https://www.googleapis.com/youtube/v3/videos?id=VO7wstoK_gI&key=AIzaSyDolRu-zJQdK38G52I_rdxqRqruHx2PSBc&part=snippet,contentDetails,statistics,status",
    function (respuesta) {
    alert(JSON.stringify(respuesta));
}).fail(function(p) {
    alert(JSON.stringify(p));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    
answered by 28.03.2017 / 20:18
source