4

我在我的应用中使用 google api 的 Objective-C 客户端添加了 youtube api v3 以将视频上传到 youtube。该应用程序的测试人员(在不同国家/地区)报告说他们无法将视频上传到 youtube。达到 100% 进度后,视频上传失败并出现后端错误。因为我在印度没有遇到这个问题。测试人员还确认,使用 youtube ios 应用程序或其他应用程序上传时,youtube 视频上传工作正常。他们还尝试从多个帐户上传视频,但结果相同。

来自设备控制台的错误日志是:

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)} 

我用来将视频上传到 youtube 的代码是:

GTMOAuth2Authentication *auth = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:YoutubeOAuthKeyChain clientID:GoogleAPIClientID clientSecret:GoogleAPIClientSecret];
if (!auth) {
    [self signInToGoogle];
}else{
    if ([auth canAuthorize] && auth.userEmail) {
        //Force the api to refresh access token if needed
        [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;
                       //uploadParameters.shouldSendUploadOnly = YES;

                       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{
                   //Error authorizing the request

                   NSLog(@"error authorizing request with error: %@", error);
               }

           });
        }]; 
    }else{
        //Refresh access token
        [self signInToGoogle];
    }

}

此问题仅在 2 周前开始。我不知道这是否是我的应用程序某些问题的服务器端问题。有没有人也有同样的问题?

4

0 回答 0