【发布时间】: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,SendOrPostCallback 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