【发布时间】:2017-12-08 14:42:38
【问题描述】:
Google documentation on this feature 很清楚,除了这不起作用(我使用的是 C#,但由于 API 本身在不同语言中是相同的,希望这将是可以理解的
private async Task FetchYtUploads()
{
UserCredential credential;
var credentialsPath = Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), @"..\..\..\..\client_id.json").Replace("file:\\", "");
using (var stream = new FileStream(credentialsPath, FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
// This OAuth 2.0 access scope allows for read-only access to the authenticated
// user's account, but not other types of account access.
new[] { YouTubeService.Scope.YoutubeReadonly },
"user",
CancellationToken.None,
new FileDataStore(this.GetType().ToString())
);
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = this.GetType().ToString()
});
var channelsListRequest = youtubeService.Channels.List("contentDetails");
channelsListRequest.Mine = true;
var channels = await channelsListRequest.ExecuteAsync(); // A list with just one item is returned
if (channels.Items.Count <= 0)
{
Console.Write("ERROR: no YT channels found.");
return;
}
var favoritesListId = channels.Items[0].ContentDetails.RelatedPlaylists.Favorites;
channels.Items 是仅包含一项的列表。 channels.Items[0].ContentDetails.RelatedPlaylists.Favorites 有一个 ID,但它与我的“收藏夹”的 URL 链接中的 ID 不同。以下请求失败,ID 为 RelatedPlaylists.Favorites,但如果我对在列表 URL 中查找的 ID 进行硬编码,则可以:
var playlistItemsListRequest = youtubeService.PlaylistItems.List("snippet");
playlistItemsListRequest.PlaylistId = favoritesListId;
playlistItemsListRequest.MaxResults = 50;
playlistItemsListRequest.PageToken = nextPageToken;
var playlistItemsListResponse = await playlistItemsListRequest.ExecuteAsync();
发生了什么事?我错过了什么吗?如何为我的“收藏”播放列表获取正确的 ID,如果不能在 playlistItemsListRequest.PlaylistId 中使用,ContentDetails.RelatedPlaylists.Favorites 是什么?
【问题讨论】:
标签: c# google-api youtube-api google-api-dotnet-client youtube-data-api