C# 如何为调用创建窗口句柄?
我正试图用youtube下身份验证用户的播放列表名称填充一个复选框列表clbWiedergabelisten。这是我的密码C# 如何为调用创建窗口句柄?,c#,youtube,youtube-api,handle,youtube-data-api,C#,Youtube,Youtube Api,Handle,Youtube Data Api,我正试图用youtube下身份验证用户的播放列表名称填充一个复选框列表clbWiedergabelisten。这是我的密码 private async Task RunAbrufen() { UserCredential credential; using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read)) { credential =
private async Task RunAbrufen()
{
UserCredential credential;
using (var stream = new FileStream("client_secrets.json", 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 playlistListRequest = youtubeService.Playlists.List("snippet");
playlistListRequest.Mine = true;
// Retrieve the contentDetails part of the playlist resource for the authenticated user's playlist.
var playlistListResponse = await playlistListRequest.ExecuteAsync();
this.Invoke((MethodInvoker)delegate
{
clbWiedergabelisten.Items.Clear();
});
foreach (var playlist in playlistListResponse.Items)
{
Console.WriteLine(playlist.Snippet.Title);
this.Invoke((MethodInvoker)delegate
{
clbWiedergabelisten.Items.Add(playlist.Snippet.Title);
});
}
}
它是由
try
{
await new Form1().RunAbrufen();
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
但每次它都说必须先创建一个窗口句柄,然后才能使用invoke。如何做到这一点?请输入等待新表单1的代码,这是您的问题。您的表单启动不正确。您将如何启动它?我使用了wait RunAbrufen;它成功了。那么代码在Form1中?那你为什么在哪里做新表格1?