我正在尝试上传简单的.txt文件作为测试。它只有4kb。这是我的代码:
-(IBAction)uploadFile:(id)sender{
if (![self.credentials canAuthorize]) {
GTMOAuth2WindowController *windowController;
windowController = [[[GTMOAuth2WindowController alloc] initWithScope:scope clientID:kClientID clientSecret:kClientSecret keychainItemName:kKeychainItemName resourceBundle:nil] autorelease];
[windowController signInSheetModalForWindow:self.window
delegate:self
finishedSelector:@selector(windowController:finishedWithAuth:error:)];
}else{
NSLog(@"Credentials already authorized.");
}
GTLDriveFile *driveFile = [GTLDriveFile object];
driveFile.title = @"myfile";
driveFile.descriptionProperty = @"Uploaded by Google Drive API test.";
driveFile.mimeType = @"text/plain";
NSData *data = [[NSFileManager defaultManager] contentsAtPath:@"/Users/Blake/Downloads/glm/util/autoexp.txt"];
GTLUploadParameters *params = [GTLUploadParameters uploadParametersWithData:data MIMEType:driveFile.mimeType];
GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:driveFile uploadParameters:params];
NSLog(@"Starting Upload to Google Drive");
[self.progressBar setHidden:FALSE];
[self.progressBar startAnimation:sender];
[self.driveService executeQuery:query completionHandler:^(GTLServiceTicket *st, GTLDriveFile *df, NSError *error){
[self.progressBar setHidden:TRUE];
if (error == nil) {
NSLog(@"File upload succeeded");
}else{
NSLog(@"Uh-oh: File upload failed");
}
}];
}
GTMOAuth2Authentication被授权,完成处理程序块永远不会执行。
我查看了Activity Monitor,它说我的应用程序在开始时发送了54个数据包。所以我想有些东西正在发送。
如果块永远不会给我一个错误,怎么能告诉我这里出了什么问题呢?
有人可以帮我理解我做错了吗?
答案 0 :(得分:0)
我最近遇到了坚持使用GTMOAuth2WindowController的问题。它无法呈现自我窗口。我花了很多时间在调试器中,发现我忘了添加WebKit.framework。它没有明确记录,并且在运行时没有任何消息(减去google dev karma))))。那么,也许你的问题呢?尝试检查您的框架集,并将其与GTL附带的示例进行比较。