Sometimes I get this error when extracting youtube videos by json, here’s an example:
XMLHttpRequest can not load https://gdata.youtube.com/feeds/api/users/IcarusTouma?&alt=json. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
I tried with jsonp, but youtube does not accept jsonp.
So extract videos from youtube.
$. getJSON ('https://gdata.youtube.com/feeds/api/videos/' + id_video + '? & alt = json', function (data) {
if (typeof data! == "undefined" && data)
{
var title = data ['entry'] ['title'] ['$ t'];
var thumb = data ['entry'] ['media $ group'] ['media $ thumbnail'] [0] ['url'];
var title = data ['entry'] ['author'] [0] ['name'] ['$ t'];
$. getJSON ('https://gdata.youtube.com/feeds/api/users/' + author + '? & alt = json', function (data) {
author_thumbnail var = data ['entry'] ['media $ thumbnail'] ['url'];
$ ('.items').append(html_carousel (thumb, title, author_thumbnail, author, 5,' youtube ', id_video, author'));
});
}
});
Having just checked the YouTube Data API reference documentation, for both JSON and the newer JSON-C formats, they both accept JSON-P, allowing you to specify the callback by the
callbackGET string parameter. This link will demonstrate that this is true:https://gdata.youtube.com/feeds/api/videos?q=baseball&v=2&alt=jsonc&callback=functionName
The long JSON object return is wrapped in the function call to
functionName, in this case. The next URL is the same call, but in the older (and somewhat deprecated) JSON format:https://gdata.youtube.com/feeds/api/videos?q=baseball&v=2&alt=json&callback=functionName
The data is a bit different, but same result set, wrapped in another call to
functionName. Now, these calls were queries to get the videos that matched the search param (“baseball”). But I’m sure perusing their reference documents (for the JSON-C and JSON formats) will yield what you need to make this work properly, as a JSONP call, specifying the callback in the query string.