Iqb*_*han 6 iphone objective-c ios google-api-objc-client
我正在尝试使用针对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?)'
Run Code Online (Sandbox Code Playgroud)
我检查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
Run Code Online (Sandbox Code Playgroud)
.
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);
};
Run Code Online (Sandbox Code Playgroud)
----------
问题是我从一个新的Gmail帐户登录,所以我需要登录youtube网站,需要创建一个频道才能上传视频到youtube.所以现在我可以在创建youtube频道后上传视频.但我怎么能为其他用户处理这种情况,任何想法
我遇到了同样的崩溃并找到了解决方案.看来,客户端得到这个崩溃也如果底层请求是错误的请求,但明确规定无响应信息(我的授权是有效的,通过该方法检查canAuthorize作为Ryan_IRL指出).
看了一下库后,我发现设置预处理器宏STRIP_GTM_FETCH_LOGGING并启用HTTPFetcher代码中某处的日志记录
#if STRIP_GTM_FETCH_LOGGING
[GTMHTTPFetcher setLoggingEnabled:YES];
#endif
Run Code Online (Sandbox Code Playgroud)
日志存储在GTMHTTPDebugLogsSimulator内的文件夹中(类似于/Users/<username>/Library/Application Support/iPhone Simulator/6.1/Applications/65451CDB-27D6-4BE2-910C-7F22D6A01832/GTMHTTPDebugLogs).在那里,您可以找到HTML格式的完整日志(...).

单击" 请求/响应日志 ",我的案例中显示了以下日志.
Response body: (201 bytes)
{
"id" : "gtl_1",
"error" : {
"message" : "Bad Request",
"code" : -32602,
"data" : [
{
"domain" : "youtube.video",
"reason" : "invalidTitle",
"locationType" : "other",
"location" : "body.snippet.title",
"message" : "Bad Request"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
坏请求与包含一些禁止字符的标题(要上传的视频)有关.修复标题解决了崩溃并正确上传了视频.在这种情况下,状态200当然是......令人沮丧且明显错误.
我对GTM图书馆以及首先使用NSAssert这种情况感到非常失望.
问题是我正在从新的 Gmail 帐户登录,因此我需要登录 YouTube 网站并需要创建一个频道,然后才能将视频上传到 YouTube。所以现在我可以在创建 YouTube 频道后上传视频。但我该如何为其他用户处理这种情况,任何想法