Google documentation on this featureはこれが機能しないことを除いてはっきりしています(私はC#を使用していますが、API自体は言語間で同じなので、これはうまくいけばユーザーの「お気に入り」プレイリストを取得する:contentDetails.relatedPlaylists.favoritesは無効なIDです
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
で失敗しても動作する場合はIハードコード、私は私のリストの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
で使用できない場合はどうなりますか?
に格納されているユーザーの名前です。しかし、私は実際に** my **アカウントにアクセスするためにクライアントを認証しました。私は正しいアカウント/チャンネルを選んだといいです。非常に奇妙な。 –
ユーザーを変更して、誤って間違ったものを選んだ可能性があります。 – DaImTo
ありがとうございました。私は私の2つのYTチャンネルのうちの1つを選んだ(2つのチャンネルがどうなっているかは分かりませんが)実際は間違っていました。 –