GData Youtube Upload Crashing for iOS [closed]
I'm trying to use the GData objective c project v1.12.0 to upload a video to youtube. I followed the following guide to get GData linked with my project: http://mischneider.net/?p=377#comment-1277
It all seems to be linked properly, but I keep getting this error message:
2011-06-23 15:06:30.729[79217:207] * Assertion failure in -GDataServiceBase fetchObjectWithURL:objectClass:objectToPost:ETag:httpMethod:delegate:didFinishSelector:completionHandler:retryInvocationValue:ticket:, /Users/aalesia88/Desktop/VOKAL/Developement/SSB-Youtube/GData/BaseClasses/GDataServiceBase.m:603 2011-06-23 15:06:30.731[79217:207] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'GDataHTTPUploadFetcher needed'
Here is my methods used in calling the upload procedure:
- (GDataServiceGoogleYouTube *)youTubeService
{
GDataServiceGoogleYouTube* service = nil;
if (!service) {
service = [[GDataServiceGoogleYouTube alloc] init];
[service setShouldCacheDatedData:YES];
[service setServiceShouldFollowNextLinks:YES];
[service setIsServiceRetryEnabled:YES];
}
SSBYoutubeCredentials *currentUser = [SSBYoutubeCredentials getCurrentUser];
NSString *username = currentUser.username;
NSString *password = currentUser.password;
if ([username length] > 0 && [password length] > 0) {
[service setUserCredentialsWithUsername:username
password:password];
} else {
// fetch unauthenticated
[service setUserCredentialsWithUsername:nil
password:nil];
}
NSString *devKey = DEVELOPER_KEY;
[service setYouTubeDeveloperKey:devKey];
return service;
}
- (void)setUploadTicket:(GDataServiceTicket *)ticket
{
if (uploadTicket != nil) {
[uploadTicket release];
}
uploadTicket = [ticket retain];
}
- (void)uploadVideoFile
{
NSString *devKey = DEVELOPER_KEY;
GDataServiceGoogleYouTube *service = [self youTubeService];
[service setYouTubeDeveloperKey:devKey];
SSBYoutubeCredentials *currentUser = [SSBYoutubeCredentials getCurrentUser];
NSString *username = currentUser.username;
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username];
// load the file data
NSString *path;
#if !TARGET_IPHONE_SIMULATOR
path = self.videoPath;
#else
path = [[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"];;
#endif
NSData *data = [NSData dataWithContentsOfFile:path];
NSString *filename = [path lastPathComponent];
// gather all the metadata needed for the mediaGroup
NSString *titleStr = self.trick;
GDataMediaTitle *title = [GDataMediaTitle textConstructWithString:titleStr];
NSString *categoryStr = @"SSB";
GDataMediaCategory *category = [GDataMediaCategory mediaCategoryWithString:categoryStr];
[category setScheme:kGDataSchemeYouTubeCategory];
NSString *descStr = self.description;
GDataMediaDescription *desc = [GDataMediaDescription textConstructWithString:descStr];
NSString *keywordsStr = @"SuperShredBros";
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:path
defaultMIMEType:@"video/mp4"];
// create the upload entry with the mediaGroup and the file
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:)];
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.delegate = self;
HUD.mode = MBProgressHUDModeDeterminate;
HUD.labelText = @"Uploading...";
[self setUploadTicket:ticket];
}
If anyone has any insight into this problem that would be very helpful.
Thanks, Anthony
The message is from GDataServiceBase.m. It indicates that the class GTMHTTPUploadFetcher is not linked in to your application.
The class may be missing due to the class file not being linked in the debug or release build target, or due to the preprocessor define GDATA_INCLUDE_YOUTUBE_SERVICE not being set, as described under "Removing Unneeded Code" at http://code.google.com/p/gdata-objectivec-client/wiki/BuildingTheLibrary
Yeah, it seemed to be a linking issue. I followed the instructions on that link to compile directly into my code and removed the classes I didn't need such as googledocs. Once I did that, everything built fine and I was able to upload.
Thanks for the help.
精彩评论