Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 向youtube视频添加评论_C#_Asp.net_Youtube Api_Gdata Api - Fatal编程技术网

C# 向youtube视频添加评论

C# 向youtube视频添加评论,c#,asp.net,youtube-api,gdata-api,C#,Asp.net,Youtube Api,Gdata Api,我的网页是在.net中开发的,我正在尝试使用以下代码向youtube视频添加评论 string lsDeveloperKey = "myDeveloperKey"; //This will ask user to login to accounts.google for posting comment if (!Request.QueryString.AllKeys.Contains("token")) { string

我的网页是在.net中开发的,我正在尝试使用以下代码向youtube视频添加评论

     string lsDeveloperKey = "myDeveloperKey";

    //This will ask user to login to accounts.google for posting comment
        if (!Request.QueryString.AllKeys.Contains("token"))
        {
            string lsUserName = "myusername";
            string lsPassword = "mypassword";

            YouTubeRequestSettings loSettings = new YouTubeRequestSettings(Keys.PortalName, lsDeveloperKey, lsUserName, lsPassword);
            YouTubeRequest loRequest = new YouTubeRequest(loSettings);

            Uri videoEntryUrl = new Uri(string.Format("{0}/{1}", Google.GData.YouTube.YouTubeQuery.DefaultVideoUri, "ofjQ_Gf5CQc"));
            Google.YouTube.Video loVideo = loRequest.Retrieve<Google.YouTube.Video>(videoEntryUrl);

            string lsRandomVideoId = getRandomId() + loVideo.VideoId;
            Session[lsRandomVideoId] = loVideo; ;

            Response.Redirect(AuthSubUtil.getRequestUrl(Request.Url.ToString() + "?v=" + lsRandomVideoId, "http://gdata.youtube.com", false, true));
        }

    //This will post a comment for logged user
        else
        {
            Session["token"] = AuthSubUtil.exchangeForSessionToken(Request.QueryString["token"], null).ToString();

            YouTubeRequestSettings loSettings = new YouTubeRequestSettings(Keys.PortalName, lsDeveloperKey, (String)            Session["token"]);
            YouTubeRequest loRequest = new YouTubeRequest(loSettings);

            Video loVideo = (Video)Session[Request.QueryString["v"]];

            Comment loComment = new Comment();
            loComment.Content = "This is my comment from my app";
            loRequest.AddComment(loVideo, loComment);
        }
    }


我在这方面做了很多工作。我不确定这里出了什么问题。任何帮助都将不胜感激

看起来您使用的是不推荐使用的ClientLogin,可能无法使用。请考虑使用OAuS2来代替,这里有一个例子:此外,YouTube将拒绝某些评论,尝试使用不带特殊字符的简单字符串

Execution of request failed:
 Stacktrace: at Google.GData.Client.GDataRequest.Execute() at
 Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter) at
 Google.GData.Client.GDataGAuthRequest.Execute() at
 Google.GData.Client.Service.EntrySend(Uri feedUri, AtomBase baseEntry,
 GDataRequestType type, AsyncSendData data) at
 Google.GData.Client.MediaService.EntrySend(Uri feedUri, AtomBase
 baseEntry, GDataRequestType type, AsyncSendData data) at
 Google.GData.Client.Service.Insert(Uri feedUri, AtomEntry newEntry,
 AsyncSendData data) at Google.GData.Client.Service.Insert[TEntry](Uri
 feedUri, TEntry entry) at
 Google.YouTube.YouTubeRequest.AddComment(Video v, Comment c) at
 YouTubeComment.Page_Load(Object sender, EventArgs e)