Youtube API - 渠道没有返回JSON数据?

问题描述 投票:0回答:1

我的javascript很难用,所以请耐心等待。

进行API调用以获取指定用户的频道数据。然后我想使用'relatedPlaylists'数据项中的id来检索所有用户视频。

目前我不认为API正在返回正确的数据。任何帮助非常感谢。

function get_playlist() {	
				get_file('https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername=petermillard1&key='+YouTubeAPIkey,
				function(data) 
					{ 
						show_channel(JSON.parse(data));
						get_videos();
				});
			}

			function show_channel(data) {					
				console.log('Channel data:' + data);							
				console.log('Uploads: ' + data.items.contentDetails.relatedPlaylists.uploads);
				videos=data.items.contentDetails.relatedPlaylists.uploads;
				console.log('Videos: ' + videos);			
			}			

		function get_videos() {
				get_file('https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2C+contentDetails&id='+ videos + '&key='+YouTubeAPIkey, 
					function(data) 
						{
							create_playlist(JSON.parse(data));
						});
			}

这是控制台中显示的内容:

Channel data:[object Object]

Uncaught TypeError: Cannot read property 'relatedPlaylists' of undefined
at show_channel (vget.html:170)
at vget.html:163
at XMLHttpRequest.XHR.onreadystatechange (vget.html:190)
javascript youtube youtube-javascript-api
1个回答
0
投票

你必须首先检查channels.list的响应是否有数据。

您遇到的错误是因为可能没有返回任何数据。

为避免检索上传播放列表,您可以执行以下操作:

  • 一旦你有了qazxsw poi,请替换突出显示的字母,如下所示:

频道:Microsoft Hololens:

Channel_id:UCT2rZIAL-zNqeK1OmLLUa6g

上传(播放列表):UUT2rZIAL-zNqeK1OmLLUa6g

然后你可以调用channel_id函数。

© www.soinside.com 2019 - 2024. All rights reserved.