0

私のウェブページは .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);
        }
    }

このコードはエラーなしで実行されます。「myusername」と「mypassword」でログインすると、コメントも投稿されます。

しかし、他のユーザーでログインすると、次のエラーが表示されます: E

Execution of request failed:

https://gdata.youtube.com/feeds/api/videos/ofjQ_Gf5CQc/comments

 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)

私はこれに多くの作業をしました。ここで何が悪いのかわかりません。どんな助けでも大歓迎です。

4

1 に答える 1

0

非推奨で機能しない可能性のあるClientLoginを使用しているようです。代わりにOAuth2の使用を検討してください。例を次に示します:http ://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/oauth2_sample/oauth2demo.cs 。また、YouTubeは特定のコメントを拒否します。特殊文字を含まない、単純な文字列を試してください。

于 2013-02-09T00:28:02.280 に答える