gpt4 book ai didi

iphone - -[GTMHTTPUploadFetcher connectionDidFinishLoading :] 中的断言失败

转载 作者:可可西里 更新时间:2023-11-01 03:54:46 24 4
gpt4 key购买 nike

我正在尝试使用适用于 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 站点并需要创建一个 channel ,然后才能将视频上传到 youtube。所以现在我可以在创建 youtube channel 后上传视频。但是我如何为其他用户处理这种情况,任何想法

最佳答案

我遇到了同样的崩溃并找到了解决方案。如果底层请求是错误请求但未明确提供响应信息(我的授权方有效并使用方法 canAuthorize 通过检查,如 Ryan_IRL 指出),客户端似乎也会发生此崩溃。

查看库后,我发现设置预处理器宏 STRIP_GTM_FETCH_LOGGING并为 HTTPFetcher 启用日志记录代码中的某处

#if STRIP_GTM_FETCH_LOGGING
[GTMHTTPFetcher setLoggingEnabled:YES];
#endif

日志存储在 GTMHTTPDebugLogs 中模拟器内的文件夹(类似于 /Users/<username>/Library/Application Support/iPhone Simulator/6.1/Applications/65451CDB-27D6-4BE2-910C-7F22D6A01832/GTMHTTPDebugLogs )。您可以在那里找到 HTML 格式的完整日志 (...)。

enter image description here

单击“请求/响应日志”,在我的案例中显示了以下日志。

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"
}
]
}
}

错误的请求与(要上传的视频的)标题有关,其中包含一些禁止使用的字符。修复标题解决了崩溃问题,视频已正确上传。在这种情况下状态 200 当然是......令人沮丧并且显然是错误的。

我也对 GTM 库以及在这种情况下使用 NSAssert 感到非常失望。

关于iphone - -[GTMHTTPUploadFetcher connectionDidFinishLoading :] 中的断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18529708/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com