【问题标题】:YouTube API - Video Upload - 401 UnauthorizedYouTube API - 视频上传 - 401 未经授权
【发布时间】:2013-04-04 12:37:56
【问题描述】:

这快把我逼疯了!我正在使用下面的代码。 90% 的时间我收到以下错误。时不时地工作没有问题。请帮忙。我检查了开发者密钥、用户名和密码。

错误:System.Net.WebException:远程服务器返回错误: (401) 未经授权。在 System.Net.HttpWebRequest.GetResponse()
在 Google.GData.Client.ResumableUpload.ResumableUploader.UploadStreamPart(Int32 partIndex, String httpMethod, Uri sessionUri, Authenticator 身份验证、流有效负载、字符串 mediaType、AsyncData 数据)
在 Google.GData.Client.ResumableUpload.ResumableUploader.UploadStream(字符串 httpMethod, Uri sessionUri, Authenticator 认证, Stream 有效载荷,字符串媒体类型,AsyncData 数据)在 Google.GData.Client.ResumableUpload.ResumableUploader.Insert(身份验证器 身份验证、AbstractEntry 有效负载、AsyncData 数据)在 Google.GData.Client.ResumableUpload.ResumableUploader.AsyncInsertWorker(AsyncResumableUploadData 数据,异步操作 asyncOp,Sen​​dOrPostCallback completionMethodDelegate) 值不能为空。参数名称: inputStream 不能为空

                **My Code:**

                newVideo.Tags.Add(new MediaCategory("Nonprofit", YouTubeNameTable.CategorySchema));
                newVideo.Description = DateTime.Now.ToShortDateString();
                newVideo.YouTubeEntry.Private = false;
                ResumableUploader m_ResumableUploader = null;
                Authenticator YouTubeAuthenticator;

                m_ResumableUploader = new ResumableUploader(100); //chunksize 1 MB
                m_ResumableUploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(m_ResumableUploader_AsyncOperationCompleted);
                m_ResumableUploader.AsyncOperationProgress += new AsyncOperationProgressEventHandler(m_ResumableUploader_AsyncOperationProgress);

                YouTubeAuthenticator = new ClientLoginAuthenticator(ConfigurationManager.AppSettings["APPLICATION_NAME"].ToString(), ServiceNames.YouTube, ConfigurationManager.AppSettings["LOGIN_USERNAME"].ToString(), ConfigurationManager.AppSettings["LOGIN_PASSWORD"].ToString());

                YouTubeAuthenticator.DeveloperKey = ConfigurationManager.AppSettings["DEVELOPER_KEY"].ToString();
                string contentType = MediaFileSource.GetContentTypeForFileName(fileName);
                newVideo.MediaSource = new MediaFileSource(filePath, contentType);

                AtomLink link = new AtomLink("http://uploads.gdata.youtube.com/resumable/feeds/api/users/" + ConfigurationManager.AppSettings["YT_USERNAME"].ToString() + "/uploads");
                link.Rel = ResumableUploader.CreateMediaRelation;
                newVideo.YouTubeEntry.Links.Add(link);

                m_ResumableUploader.InsertAsync(YouTubeAuthenticator, newVideo.YouTubeEntry, new object());

我想我应该添加.. 它在最后一行 ytr.ParseVideo(e.ResponseStream); 上中断;

void m_ResumableUploader_AsyncOperationCompleted(object sender, AsyncOperationCompletedEventArgs e)
        {

                YouTubeRequestSettings ys = new YouTubeRequestSettings(ConfigurationManager.AppSettings["APPLICATION_NAME"].ToString(),
                   ConfigurationManager.AppSettings["DEVELOPER_KEY"].ToString(), ConfigurationManager.AppSettings["LOGIN_USERNAME"].ToString(),
                                                   ConfigurationManager.AppSettings["LOGIN_PASSWORD"].ToString());

                YouTubeRequest ytr = new YouTubeRequest(ys);
                Video v = ytr.ParseVideo(e.ResponseStream);
}

【问题讨论】:

    标签: c# youtube-api


    【解决方案1】:

    我的猜测是您没有上传到与您拥有的存储凭据相对应的帐户。一般来说,您不应该在 GData API v2 代码中执行 ConfigurationManager.AppSettings["YT_USERNAME"].ToString() 之类的操作;相反,您应该使用值 default 作为 URL 的用户部分,它指的是当前经过身份验证的用户。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-26
      • 2013-12-09
      • 2017-11-28
      • 1970-01-01
      • 2018-09-12
      • 1970-01-01
      • 2019-03-07
      • 2017-09-27
      相关资源
      最近更新 更多