Using Gdata api 2.1.0.0 and YT SDK 2.1.0.0, with WPF client uploading a caption file, I get an exception saying that the content language header is not set (as required by the api). Using the RequestFactory to create a GDataRequest, I can set the content type and slug fine, but there's nowhere I can see to setHeaders on the Gdata request, that seems to have disappeared... Please advise or point me in the right direction, I've tried to understand this pattern & have looked at the samples I can, no luck...
Error response string:
Execution of request failed: https://gdata.youtube.com/feeds/api/videos/WWfvx47xxxx/captions
<errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>InvalidEntryException</code><internalReason>No Content-Language header provided.</internalReason></error></errors>
Code:
private void uploadCaptionV2()
{
YouTubeService service = new YouTubeService(applicationName, developerKey);
service.Credentials = new GDataCredentials(userName, password);
YouTubeRequestSettings settings = new YouTubeRequestSettings(applicationName, developerKey, userName, password);
GDataCredentials credentials = service.Credentials;
ClientLoginAuthenticator cla = new ClientLoginAuthenticator(applicationName, ServiceNames.YouTube, credentials);
String uploadLoc = "https://gdata.youtube.com/feeds/api/captions/" + videoId + "/captions HTTP/1.1";
uploadLoc = "https://gdata.youtube.com/feeds/api/captions/" + videoId;
uploadLoc = "https://gdata.youtube.com/feeds/api/videos/" + videoId + "/captions";
Uri uriTarget = new Uri(uploadLoc);
GDataRequest gdr = (GDataRequest) service.RequestFactory.CreateRequest(GDataRequestType.Insert, uriTarget);
String contentType = "application/vnd.youtube.timedtext; charset=UTF-8";
gdr.ContentType = contentType;
gdr.Credentials = credentials;
gdr.Slug = "Title of captions";
String captionFilePath = "D:\\system\\temp\\Captions.txt";
Stream str = new FileStream(captionFilePath, FileMode.Open);
MemoryStream mem = new MemoryStream();
CopyStream(str, mem);
byte[] buffer = mem.GetBuffer();
long length = mem.Length;
Stream rqStream = gdr.GetRequestStream();
foreach (byte b in buffer)
{
rqStream.WriteByte(b);
}
try
{
gdr.Execute();
}
catch (GDataRequestException gdrEx)
{
appendLog(gdrEx.Message + gdrEx.ResponseString);
}
catch (Exception ex)
{
}
}
--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To view this discussion on the web visit https://groups.google.com/d/msg/youtube-api-gdata/-/a7G5M1m-YVcJ.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.
No comments:
Post a Comment