Google documentation on this feature非常清楚,除了它不能工作之外(我使用的是C#,但是因为它本身在不同的语言中是一样的,所以希望它是可以理解的
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,但它与我的“收藏夹”链接中的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为我的“收藏”播放列表,以及什么是ContentDetails.RelatedPlaylists.Favorites,如果它不能在playlistItemsListRequest.PlaylistId中使用
发布于 2017-07-05 14:46:58
您需要记住,YouTube应用程序接口是基于通道的。当您使用应用程序向API进行身份验证时,系统会要求您选择一个通道。您拥有的身份验证将仅授予您访问此通道的权限。
如果你想访问一个不同的通道,那么你必须重新验证你的应用程序并选择一个不同的通道。
提示:将"user“更改为其他值,它将再次请求auth。user是在%appData%中存储凭据的用户的名称
https://stackoverflow.com/questions/44917598
复制相似问题