Not getting list of YouTube videos
I have followed a tutorial on how to use the youtube gdata. Populating a listview with videos from youtube and a onclick. The source code is available on:
http://blog.blundell-apps.com/click-item-in-a-listview-to-show-youtube-video/
Once i have changed the YouTube GData link
from:
https://gdata.youtube.com/feeds/api/videos?author="+username+"&v=2&alt=jsonc
to :
http://gdata.youtube.com/feeds/api/users/GoogleDevelopers/uploads
i am not getting list of videos, why?
Reason is it's not working because :
From this URL :
https://gdata.youtube.com/feeds/api/videos?author="+username+"&v=2&alt=jsonc
you are getting JSON String in Response for gdata.youtube.com
and
In this URL :
http://gdata.youtube.com/feeds/api/users/GoogleDevelopers/uploads
you are getting Rss XML in Response for gdata.youtube.com
SOLUTION :
to make it working you will need to change JSON String parsing in GetYouTubeUserVideosTask
class to XML parsing
OR
use this URL for getting data in JSON format :
http://gdata.youtube.com/feeds/api/users/GoogleDevelopers/uploads?v=2&alt=jsonc
and use this tutorial to known how we parse json in android :
http://www.androidhive.info/2012/01/android-json-parsing-tutorial/
这是新的谷歌API版本3的完美代码
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="application/javascript">
$(document).ready(function () {
var channelName = 'PochicaKing';
$.get(
"https://www.googleapis.com/youtube/v3/channels", {
part: 'contentDetails',
forUsername: channelName,
// mine: true,
// access_token: 'ya29.cQEoJbvUmAMT6xJFgDoi4gq0EW8O5Q_9ZqLtNUay0AbNh-mldmNh5mlicarLx00AHxL_O6Vur8M3Bw',
key: 'AIzaSyARSqGexKgNt0BdHUJBXg2pnxMGgYXrszw'
},
function (data) {
$.each(data.items, function (i, item) {
console.log(item);
pid = item.contentDetails.relatedPlaylists.likes;
gitVids(pid);
});
}
);
function gitVids(pid) {
$.get(
"https://www.googleapis.com/youtube/v3/playlistItems", {
part: 'snippet',
maxResults: 5,
playlistId: pid,
key: 'AIzaSyARSqGexKgNt0BdHUJBXg2pnxMGgYXrszw'
},
function (data) {
var output;
$.each(data.items, function (i, item) {
// console.log(item);
vidTitle = item.snippet.title;
vidId = item.snippet.resourceId.videoId;
output = '<li><iframe width="420" height="315"src="http://www.youtube.com/embed/' + vidId + '"></iframe></li>'
$('#results').append(output);
});
}
);
}
});
</script>
</head>
<body>
<ul id="results"></ul>
</body>
</html>
Api V2 is opsolete. Use V3
https://www.googleapis.com/youtube/v3/search?part=snippet&q= QUERY &maxResults=50&key= YOURKEYGOOGLECONSOLE
上一篇: YouTube API“q”参数损坏?
下一篇: 没有获得YouTube视频列表