YouTube API, c# .net -从YouTube获取视频信息有时会失败

本文关键字:YouTube 信息 失败 视频 API net 获取 | 更新日期: 2023-09-27 18:09:18

我试图在YouTube上的视频中添加评论,有时当我得到一个视频添加评论时,YouTube给我发送以下错误:请求执行失败:http://gdata.youtube.com/feeds/api/videos/ceVlltPBcHg/comments

异常的内部消息是:"远程服务器返回了一个错误:(403)Forbidden。"

public bool commentVideo(string videoId)
{
       Uri Url = new Uri("http://gdata.youtube.com/feeds/api/videos/" + videoId);
       YouTubeRequestSettings s = new YouTubeRequestSettings(AppName, ApiKey,UserName,
                                                                  Password);
       s.Timeout = 10000000;
       YouTubeRequest account  = new YouTubeRequest(s);
       account.Proxy = GetProxyForUser(user);
       Video video = account.Retrieve<Video>(Url);//some times got exception
       string rating = commentRepository.getRating();
       Comment c = new Comment();
       c.Content = commentRepository.getComment();
       account.AddComment(video, c);
       Console.WriteLine("Comment successfully added to : " + videoId);
       return true;
}

我的代码有什么问题?

YouTube API, c# .net -从YouTube获取视频信息有时会失败

似乎谷歌的qouta安全规则返回错误到我的代码。当我长时间使用代码时,代码可以正常工作。