如何创建一个窗口句柄进行调用?

时间:2015-09-04 21:11:42

标签: 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 = 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);
}

但是每次它都说在调用之前必须创建一个窗口句柄。怎么做?

0 个答案:

没有答案