我正在尝试使用用于 Objective-C 的 Google API 客户端库在 youtube 上上传视频,我使用下面给出的代码,但它一直给我这个错误,我试图在 youtube 示例项目上再次运行我的帐户,它给出了同样的结果错误。
谁能指导我哪里有问题。我检查 YouTube Data API v3 是否在服务页面上。
*** Assertion failure in -[GTMHTTPUploadFetcher connectionDidFinishLoading:], /Volumes/data/Work/test/DLNew/DL/google-api-objectivec-client-read-only/Source/HTTPFetcher/GTMHTTPUploadFetcher.m:399
2013-08-30 14:28:31.399 [1250:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unexpected response data (uploading to the wrong URL?)'
我检查了 GTMHTTPUploadFetcher 类的代码,它在此链接上使应用程序崩溃
`#if DEBUG
// The initial response of the resumable upload protocol should have an
// empty body
//
// This assert typically happens because the upload create/edit link URL was
// not supplied with the request, and the server is thus expecting a non-
// resumable request/response.
NSAssert([[self downloadedData] length] == 0,
@"unexpected response data (uploading to the wrong URL?)");
#endif
.
NSString *path = [[NSUserDefaults standardUserDefaults] objectForKey:@"MOVIEPATH"];
NSString *filename = [path lastPathComponent];
NSString *mimeType = [self MIMETypeForFilename:filename defaultMIMEType:@"video/mp4"];
NSError *eel=nil;
NSFileHandle *handle = [NSFileHandle fileHandleForReadingFromURL:[NSURL URLWithString:path] error:&eel];
NSLog(@"error is %@",eel);
if (!handle)
{
NSLog(@"Failed to open file for reading");
return;
}
GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
service.authorizer = self.gTMOAuth2Authentication;
GTLUploadParameters *params = [GTLUploadParameters uploadParametersWithFileHandle:handle MIMEType:mimeType];
GTLYouTubeVideoSnippet *snippet = [GTLYouTubeVideoSnippet object];
snippet.title = @"Test title";
snippet.descriptionProperty = @"Test description";
snippet.tags = [NSArray arrayWithObjects:@"TestOne", @"TestTwo" ,nil];
snippet.categoryId = @"17";
GTLYouTubeVideoStatus *status = [GTLYouTubeVideoStatus object];
status.privacyStatus = @"private";
GTLYouTubeVideo *video2 = [GTLYouTubeVideo object];
video2.snippet = snippet;
video2.status = status;
GTLQueryYouTube *query = [GTLQueryYouTube queryForVideosInsertWithObject:video2 part:@"snippet,status" uploadParameters:params];
// Perform the upload
GTLServiceTicket *ticket = [service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error)
{
if (error)
{
NSLog(@"ERROR: %@", error);
return;
}
NSLog(@"SUCCESS! %@; %@;", ticket, object);
}];
ticket.uploadProgressBlock = ^(GTLServiceTicket *ticket, unsigned long long numberOfBytesRead, unsigned long long dataLength)
{
NSLog(@"%lld / %lld", numberOfBytesRead, dataLength);
};
----------
问题是我从一个新的 gmail 帐户登录,所以我需要登录 youtube 网站并需要创建一个频道,然后才能将视频上传到 youtube。所以现在我可以在创建 youtube 频道后上传视频。但是我如何为其他用户处理这种情况,任何想法