如何使用 youtube api v3 获取我所有订阅的频道
How can I get all my subscribed channel using youtube api v3
我是 youtube api v3 的新手,在获取我所有订阅的频道时遇到问题。我订阅了 65 个频道,但每次 api 通话只能获得 50 个频道。那么,有没有办法得到所有?
另一件事是,我有一个 channelID,在我订阅的频道列表中是否有 api 可以查看此频道?
Youtube API 每次调用限制 50 个结果。如果您问是否可以在同一个电话中获得所有 65 个,那么答案是否定的。但是,如果您的意思是是否可以检索所有 65 个,那么可以。您需要使用 nextPageToken 参数值并将其传递给 pageToken 参数,这将带您进入下一页。在代码中可以这样处理(如documentation所示):
var nextPageToken = '';
// This loop retrieves a set of playlist items and checks the nextPageToken
// in the response to determine whether the list contains additional items.
// It repeats that process until it has retrieved all of the items in the list.
while (nextPageToken != null) {
var playlistResponse = YouTube.PlaylistItems.list('snippet', {
playlistId: playlistId,
maxResults: 25,
pageToken: nextPageToken
});
关于您的 ChannelID 问题,根据您的描述,我了解到您想检查您是否订阅了某个特定的频道,以防您拥有它的 ID。相信YoutubeAPI的Activities方法应该可以帮到你。看看contentDetails.subscription属性。希望能解决您的问题。
我是 youtube api v3 的新手,在获取我所有订阅的频道时遇到问题。我订阅了 65 个频道,但每次 api 通话只能获得 50 个频道。那么,有没有办法得到所有?
另一件事是,我有一个 channelID,在我订阅的频道列表中是否有 api 可以查看此频道?
Youtube API 每次调用限制 50 个结果。如果您问是否可以在同一个电话中获得所有 65 个,那么答案是否定的。但是,如果您的意思是是否可以检索所有 65 个,那么可以。您需要使用 nextPageToken 参数值并将其传递给 pageToken 参数,这将带您进入下一页。在代码中可以这样处理(如documentation所示):
var nextPageToken = '';
// This loop retrieves a set of playlist items and checks the nextPageToken
// in the response to determine whether the list contains additional items.
// It repeats that process until it has retrieved all of the items in the list.
while (nextPageToken != null) {
var playlistResponse = YouTube.PlaylistItems.list('snippet', {
playlistId: playlistId,
maxResults: 25,
pageToken: nextPageToken
});
关于您的 ChannelID 问题,根据您的描述,我了解到您想检查您是否订阅了某个特定的频道,以防您拥有它的 ID。相信YoutubeAPI的Activities方法应该可以帮到你。看看contentDetails.subscription属性。希望能解决您的问题。