适合边缘 [英] Fitting the edges
问题描述
大家好,
我是新来的C#编程的新手很抱歉如果我丢失的东西是b $ b不允许在论坛中使用。
我正在尝试实施一种软件,可以(在第一阶段)显示YouTube用户的播放列表列表,
使用Windows窗体应用程序。
我看到一些视频和文章很安静,并查看了Google API网站,但我有遗漏了一些东西。
我基于这个网站上出现的代码 - https://automatetheplanet.com/youtube-playlists-api-csharp -code /
$
这是我开始使用的形式 -
Hi to all,
I'm new here and new to C# programming so sorry if I'm
missing things which aren't allowed in the forum.
I'm trying to implement a software which can (at the first stage) display a list of a YouTube user's playlists,
using a windows form application.
I've see quiet a few videos and articles, and viewed the Google API site, but I have some things missing out.
I'm Basing myself on the code as appears in this site - https://automatetheplanet.com/youtube-playlists-api-csharp-code/
This is what I've started with in at my form -
namespace YouTubeTest
{
public partial class FormGetPlaylist : Form
{
public FormGetPlaylist()
{
InitializeComponent();
}
private void buttonGoclick_Click(object sender, EventArgs e)
{
listBoxPlaylists.Items.Clear();
string userEmail = textBoxUsersName.Text;
List<YouTubePlayList>
//YouTubeVideo[] playlists = YouTubeAPI.GetPlaylist(userEmail);
foreach (var playlist in playlists)
{
listBoxPlaylists.Items.Add(playlist);
}
}
}
}
如何与下面的"GetUserPlayLists"功能进行交互,以获取播放列表列表?
下面的代码部分存在于名称空间YouTubePlaylistAPI下的另一个文件"YouTubeServiceClient"中:
how do I interact with the function 'GetUserPlayLists' below so to get the list of playlists ?
the part of code below exists in a different file , 'YouTubeServiceClient', under the namespace YouTubePlaylistAPI:
...
public List<YouTubePlayList> GetUserPlayLists(string userEmail)
{
var playLists = new List<YouTubePlayList>();
try
{
var service = new YouTubeServiceClient();
service.GetUserPlayListsAsync(userEmail, playLists).Wait();
}
catch (AggregateException ex)
{
foreach (var e in ex.InnerExceptions)
{
//TODO: Add Logging
}
}
return playLists;
}
....
此外,我是否需要在"TODO"评论中添加代码或者是可选的?
谢谢提前,
Amitai
besides, Do I need to added code in the 'TODO' comment or that's optional?
Thanks in advance,
Amitai
推荐答案
问候amitaiwe。
Greetings amitaiwe.
回答你的第二个问题,它是可选的。我们的想法是,您可以将任何错误的详细信息写入文件或事件日志,这样如果出现问题,您可以查看它是什么。但是这不是程序运行所必需的。
To answer your second question, it's optional. The idea is that you can write the details of any error to a file or an event log, so that if something goes wrong you can look up what it was. But that is not necessary for the program to run.
要回答第一个问题,您需要实例化该方法所在的类才能调用该方法。为此,您可以将带有命名空间的using语句添加到表单的代码中,或者使用命名空间为类添加前缀。
To answer your first question, you will need to instantiate the class that the method is in to be able to call the method. To do that, you can either add a using statement with the namespace to your form's code, or prefix the class with the namespace.
例如,如果方法是调用的类的一部分MyClass,就像这样......
For example, if the method is part of a class called MyClass, like this...
namespace YouTubePlaylistAPI
{
public class MyClass
{
// Other code is in here.
public List<YouTubePlayList> GetUserPlayLists(string userEmail)
{
var playLists = new List<YouTubePlayList>();
try
{
var service = new YouTubeServiceClient();
service.GetUserPlayListsAsync(userEmail, playLists).Wait();
}
catch (AggregateException ex)
{
foreach (var e in ex.InnerExceptions)
{
//TODO: Add Logging
}
}
return playLists;
}
}
}
...你可以这样称呼它。
... You could call it like this.
// Use the correct namespace.
using YouTubePlaylistAPI;
namespace YouTubeTest
{
public partial class FormGetPlaylist : Form
{
// Instantiate the class we want to use.
MyClass mc = new MyClass();
public FormGetPlaylist()
{
InitializeComponent();
}
private void buttonGoclick_Click(object sender, EventArgs e)
{
listBoxPlaylists.Items.Clear();
string userEmail = textBoxUsersName.Text;
// Use our instance of the class.
List<YouTubePlayList> = mc.GetUserPlayLists(usermail);
foreach (var playlist in playlists)
{
listBoxPlaylists.Items.Add(playlist);
}
}
}
}
如果您没有为命名空间输入using语句,则可以使用命名空间作为前缀来实例化该类,如下所示。
If you don't put in the using statement for the namespace, you can instantiate the class by using the namespace as a prefix, like so.
YouTubePlaylistAPI.MyClass mc = new YouTubePlaylist.MyClass();
这篇关于适合边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!