Authentication 需要验证码的youtube api C#

Authentication 需要验证码的youtube api C#,authentication,youtube-api,youtube.net-api,Authentication,Youtube Api,Youtube.net Api,每次我请求将视频发送到youtube API时,我都会这样做: public Video GetVideo(string videoId) { YouTubeRequest request = new YouTubeRequest(settings); Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + videoId); return request.Retrieve&

每次我请求将视频发送到youtube API时,我都会这样做:

public Video GetVideo(string videoId)
{
    YouTubeRequest request = new YouTubeRequest(settings);

    Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + videoId);

    return request.Retrieve<Video>(videoEntryUrl);
}
public Video GetVideo(字符串videoId)
{
YouTuberRequest请求=新建YouTuberRequest(设置);
Uri videoEntryUrl=新Uri(“http://gdata.youtube.com/feeds/api/videos/“+videoId);
返回请求。检索(videoEntryUrl);
}
有时我会遇到一个例外,说“需要验证码”。我想知道构建YouTuberRequest是否要求每次调用GetVideo时都使用身份验证令牌,因此我得到了这个例外。可能吗?我怎样才能避免这个例外?我不是说用试抓的方式来处理它


谢谢

是;有几种方法可以重用ClientLogin令牌。请参阅中的场景4,并查看中的“收回身份验证令牌”部分


更妙的是,我建议您移动到OAuth 2,而不是像那篇博文中提到的ClientLogin。

现在我正在做这样的事情(缓存令牌):request=newYouTuberRequest(设置);字符串标记=Environment.Cache.Lookup(“YoutubeToken-”+user);if(String.IsNullOrEmpty(token)){token=request.Service.QueryClientLoginToken();Environment.Cache.AddOrUpdateObject(“YoutubeToken-”+user,token);}request.Service.SetAuthenticationToken(token);你认为这足够吗??谢谢我的意思是,这似乎是对的,但您大概已经能够运行该代码并验证它是否重用了缓存的令牌,对吗?当然可以,甚至对其进行了调试,但我对此不是很确定。非常感谢杰夫!