这真让我抓狂!我正在使用下面的代码。90%的时间我收到以下错误。时不时地工作没有问题。请帮忙。我检查了开发人员密钥、用户名和密码。
错误:System.Net.WebException:远程服务器返回错误:(401)未经授权。在 System.Net.HttpWebRequest.GetResponse()
在 Google.GData.Client.ResumableUpload.ResumableUploader.UploadStreamPart(Int32 partIndex, String httpMethod, Uri sessionUri, Authenticator authentication, Stream payload, String mediaType, AsyncData data)
Google.GData.Client.ResumableUpload.ResumableUploader.UploadStream(String httpMethod, Uri sessionUri, Authenticator authentication, Stream payload, String mediaType, AsyncData data) at Google.GData.Client.ResumableUpload.ResumableUploader.Insert(Authenticator authentication, AbstractEntry payload, AsyncData data) 在 Google.GData.Client.ResumableUpload.ResumableUploader.AsyncInsertWorker(AsyncResumableUploadData data, AsyncOperation 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);
}