我正在尝试将在我的应用中拍摄的视频上传到 YouTube。我已将标题、用户名、密码、电影路径、长度、关键字和类别与我的应用程序密钥联系起来。然而,当我尝试上传时,我收到以下消息。
2012-12-02 21:29:33.235 我的小世界应用程序 [12790:907] * -GDataServiceBase fetchObjectWithURL:objectClass:objectToPost:ETag:httpMethod:delegate:didFinishSelector:completionHandler:retryInvocationValue:ticket:, /Users/nilesh 中的断言失败/gdata-objectivec-client-read-only/Source/BaseClasses/GDataServiceBase.m:549 2012-12-02 21:29:33.238 my little world app[12790:907] *由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:'需要 GTMHTTPUploadFetcher'
这是我用来尝试上传的代码。
- (IBAction)publish: (id) sender;{
self.mProgressView.hidden =NO;
NSString *audioName = [pictureDictionary4 objectForKey:@"photoVideokey"];
NSArray *pathsa = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectorya = [pathsa objectAtIndex:0];
//Get a full path to the image in the documents directory.
NSString *fullPatha = [documentsDirectorya stringByAppendingPathComponent:audioName];
NSError *error = nil;
NSDictionary *attributes = [[NSFileManager defaultManager]
attributesOfItemAtPath:fullPatha error:&error];
if (!error) {
NSNumber *size = [attributes objectForKey:NSFileSize];
}
NSString *devKey = @"xxxxxx";
GDataServiceGoogleYouTube *service = [self youTubeService];
[service setYouTubeDeveloperKey:devKey];
NSString *username = self.accountView.text;
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username];
NSData *data = [NSData dataWithContentsOfFile:fullPatha];
NSString *filename = [pictureDictionary4 objectForKey:@"photoVideokey"];
// gather all the metadata needed for the mediaGroup
NSString *titleStr =self.movieNameField.text;
GDataMediaTitle *title = [GDataMediaTitle textConstructWithString:titleStr];
NSString *categoryStr = self.catagoryField.text;
GDataMediaCategory *category = [GDataMediaCategory mediaCategoryWithString:categoryStr];
[category setScheme:kGDataSchemeYouTubeCategory];
NSString *descStr = self.descpView.text;
GDataMediaDescription *desc = [GDataMediaDescription textConstructWithString:descStr];
NSString *keywordsStr = self.tagsField.text;
GDataMediaKeywords *keywords = [GDataMediaKeywords keywordsWithString:keywordsStr];
BOOL isPrivate = NO;
GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];
[mediaGroup setMediaTitle:title];
[mediaGroup setMediaDescription:desc];
[mediaGroup addMediaCategory:category];
[mediaGroup setMediaKeywords:keywords];
[mediaGroup setIsPrivate:isPrivate];
NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:fullPatha
defaultMIMEType:@"video/mp4"];
// create the upload entry with the mediaGroup and the file data
GDataEntryYouTubeUpload *entry;
entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup
data:data
MIMEType:mimeType
slug:filename];
SEL progressSel = @selector(ticket:hasDeliveredByteCount:ofTotalByteCount:);
[service setServiceUploadProgressSelector:progressSel];
GDataServiceTicket *ticket;
ticket = [service fetchEntryByInsertingEntry:entry
forFeedURL:url
delegate:self
didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)];
[self setUploadTicket:ticket];
NSLog(@"%@",length.text);
NSLog(@"%@",number.text);
NSLog(@"%@",accountView.text);
NSLog(@"%@",tagsField.text);
NSLog(@"%@",catagoryField.text);
NSLog(@"%@",movieNameField.text);
NSLog(@"%@",descpView.text);
NSLog(@"%@",PasswordDisplayField.text);
NSLog(@"%@",ViewingField.text);
NSLog(@"%@",username);
NSLog(@"%@",url);
NSLog(@"%@",filename);
NSLog(@"%@",titleStr);
NSLog(@"%@",category);
NSLog(@"%@",categoryStr);
NSLog(@"%@",descStr);
NSLog(@"%@",desc);
NSLog(@"%@",keywords);
NSLog(@"%@",keywords);
NSLog(@"%@",keywordsStr);
}
- (GDataServiceGoogleYouTube *)youTubeService {
static GDataServiceGoogleYouTube* service = nil;
if (!service) {
service = [[GDataServiceGoogleYouTube alloc] init];
[service setServiceShouldFollowNextLinks:YES];
[service setIsServiceRetryEnabled:YES];
}
// update the username/password each time the service is requested
NSString *username = [accountView text];
NSString *password = [PasswordDisplayField text];
if ([username length] > 0 && [password length] > 0) {
[service setUserCredentialsWithUsername:username
password:password];
} else {
// fetch unauthenticated
[service setUserCredentialsWithUsername:nil
password:nil];
}
NSString *devKey = @"AI39si5rnzA1o82wzQj_kFFJBQRNEPv29OKD9hx6RxLPzvacvfvLFi_uI9eNj0uq8Cul8VQnBbDs4CAvq7ViKq-RnVCgh3OVBQ";
[service setYouTubeDeveloperKey:devKey];
return service;
}
// progress callback
- (void)ticket:(GDataServiceTicket *)ticket
hasDeliveredByteCount:(unsigned long long)numberOfBytesRead
ofTotalByteCount:(unsigned long long)dataLength {
[mProgressView setProgress:(double)numberOfBytesRead / (double)dataLength];
}
// upload callback
- (void)uploadTicket:(GDataServiceTicket *)ticket
finishedWithEntry:(GDataEntryYouTubeVideo *)videoEntry
error:(NSError *)error {
if (error == nil) {
// tell the user that the add worked
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Uploaded!"
message:[NSString stringWithFormat:@"%@ succesfully uploaded",
[[videoEntry title] stringValue]]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!"
message:[NSString stringWithFormat:@"Error: %@",
[error description]]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
}
[mProgressView setProgress: 0.0];
[self setUploadTicket:nil];
}
#pragma mark -
#pragma mark Setters
- (GDataServiceTicket *)uploadTicket {
return mUploadTicket;
}
- (void)setUploadTicket:(GDataServiceTicket *)ticket {
mUploadTicket = ticket;
}
我真的很感激这方面的一些方向。谢谢