添加使用YouTube API随机未能在.NET评论 [英] Adding comments with the Youtube API randomly failing in .NET

查看:106
本文介绍了添加使用YouTube API随机未能在.NET评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是C#.net 2.0的winform在2010年,我已经加入登录并发表评论的能力的用户。我复制如何发表评论的.NET开发人员指南,但我想发表评论时,得到随机的,但频繁的异常。起初我以为这可能是因为有一些问题与使用,而不是YouTube的登录名谷歌的电子邮件,来解决这个问题,当用户成功地登录时,我要求的配置文件,获取用户名,并创建一个新的YouTube的设置类,并给予与用户配置文件名称适当的凭据。然而,这并没有解决问题,意见仍然有效零星。这里是code,基本上处理登录。

I am using a C# .NET 2.0 winform in 2010, I have added the ability for a user to log in and post comments. I copied the .NET developer guide in how to post comments but I am getting random but frequent exceptions when trying to post comments. At first I thought it might be because there is some issue with using a google e-mail instead of the youtube log in name, to get around this when a user succesfully logs in I request the profile, get the user name and create a new youtube settings class and give the appropriate credentials with the users profile name. This however hasn't resolved the issue, the comments still work sporadically. Here is the code that basically handles logging in.

       youtubeService.setUserCredentials(userBox.Text, passwordBox.Text);

        try
        {
            String strAuth = youtubeService.QueryClientLoginToken();
        }
        catch (Exception ex)
        {
        }         

以上code是在一个单独的形式,承载YouTube视频基本上看起来,看看这个过程已经完成,并抓住了用户名,用于登录的密码并设置新的设置形式:

The above code is in a seperate form, the form that hosts the youtube video basically looks to see if this process has been completed and grabs the username, password used to log in and sets the new settings:

                m_LoggedInSettings = new YouTubeRequestSettings(myappname, mydevkey, username, password);
                m_LoggedInRequest = new YouTubeRequest(m_LoggedInSettings); 

这则用于添加注释:

                Comment userComment = new Comment();
                userComment.Content = commentText;
                m_LoggedInRequest.AddComment(youtubevideo, userComment);   

当它失败我得到了以下内容:

When it fails I get the following:

{的要求执行失败: https://gdata.youtube .COM /供稿/ API /视频/ T-8K8Hj8bxE /评论}

{"Execution of request failed: https://gdata.youtube.com/feeds/api/videos/t-8K8Hj8bxE/comments"}

通过以​​下方式:

{远程服务器返回错误:(403)禁止}

{"The remote server returned an error: (403) Forbidden."}

状态code:

System.Net.HttpStatus code.Forbidden

System.Net.HttpStatusCode.Forbidden

状态说明:

禁止

有几件事情浮现在脑海中,我没有一个适当的注销发送任何东西到YouTube的形式实现在一分钟(这是需要?),所以它可能是我已经登录多次,这是莫名其妙萎靡不振的youtubes的一面呢?这也可能是因为我基本上是建立新的设置,而不是用来获得视频/评论请求对象,也许从正常设置文件所采取的视频(不含税)是给问题或类似的东西?说实话,我没有得到什么线索是错误的,任何帮助将不胜appriecated。

A few things come to mind, I do not have a proper log out that sends anything to youtube implimented at the minute (is this needed?), so it may be that I've logged in multiple times and that is somehow flagging on youtubes side? It could also be that I am essentially creating new settings and request objects that weren't used to get the video/comments and maybe the video taken from the normal settings file (with no log in) is giving problems or something like that? To be honest, I haven't got a clue what is wrong and any help would be greatly appriecated.

推荐答案

好了,所以我想通了,他们被示数的原因是因为我尝试后连续意见太快了,但是我不知道什么是超时对于能够发表更多的评论。

Okay, so I figured out that the reason they were erroring is because I was trying to post consecutive comments too fast, however I don't know what the timeout is for being able to post more comments.

这篇关于添加使用YouTube API随机未能在.NET评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆