I added youtube api v3 using the google api objective-C client in my application for uploading videos to youtube. Application testers (in different countries) report that they cannot upload videos to YouTube. Video upload failed, reaching 100% progress with an error. Where I do not encounter this problem at my end here in India. Testers also confirm that downloading youtube videos works great when downloading using the YouTube ios application or another application. They also tried to download videos from multiple accounts, but with the same result.
Error log from the device console:
Error Domain=com.google.GTLJSONRPCErrorDomain Code=-32099 "The operation couldn’t be completed. (Backend Error)" UserInfo=0x2438c380 {error=Backend Error, GTLStructuredError=GTLErrorObject 0x27ea3990: {message:"Backend Error" code:-32099 data:[1]}, NSLocalizedFailureReason=(Backend Error)}
and my code that I use to upload videos to youtube is:
GTMOAuth2Authentication *auth = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:YoutubeOAuthKeyChain clientID:GoogleAPIClientID clientSecret:GoogleAPIClientSecret];
if (!auth) {
[self signInToGoogle];
}else{
if ([auth canAuthorize] && auth.userEmail) {
[auth authorizeRequest:Nil completionHandler:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (!error) {
NSLog(@"Youtube: App authorized. Uploading video now");
self.youTubeService.authorizer = auth;
GTLYouTubeVideoStatus *status = [GTLYouTubeVideoStatus object];
status.privacyStatus = @"public";
GTLYouTubeVideoSnippet *snippet = [GTLYouTubeVideoSnippet object];
snippet.title = _captionTextView.text;
snippet.descriptionProperty = @"This is a test video";
GTLYouTubeVideo *video = [GTLYouTubeVideo object];
video.status = status;
video.snippet = snippet;
NSString *filename = [_moviePath lastPathComponent];
NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:_moviePath];
if (fileHandle) {
NSString *mimeType = [self MIMETypeForFilename:filename
defaultMIMEType:@"video/mp4"];
GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithFileHandle:fileHandle MIMEType:mimeType];
uploadParameters.uploadLocationURL = nil;
GTLQueryYouTube *query = [GTLQueryYouTube queryForVideosInsertWithObject:video part:@"snippet,status" uploadParameters:uploadParameters];
GTLServiceYouTube *service = self.youTubeService;
GTLServiceTicket *ticket = [service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (!error) {
NSLog(@"Youtube video upload completed ");
}else{
NSLog(@"error completing request with error: %@", error);
}
});
}];
[ticket setUploadProgressBlock:^(GTLServiceTicket *ticket, unsigned long long totalBytesWritten, unsigned long long totalBytesExpectedToWrite) {
float progress = ((float)totalBytesWritten / (float)totalBytesExpectedToWrite) * 100.0f;
NSLog(@"%f %% uploaded");
}];
}
}else{
NSLog(@"error authorizing request with error: %@", error);
}
});
}];
}else{
[self signInToGoogle];
}
}
2 . , . - ?