我試圖使用GData目標c項目v1.12.0上傳視頻到YouTube。我跟着下面的指導,得到的GData與我聯繫的項目: http://mischneider.net/?p=377#comment-1277GData Youtube上傳崩潰的iOS
這一切似乎正確地聯繫在一起,但我不斷收到此錯誤信息:
2011-06-23 15:06: 30.729 [79217:207] *在-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] *由於未捕獲的異常'NSInternalInconsistencyException',原因:'GDataHTTPUploadFetcher needed'
這裏是調用上傳過程中使用我的方法:
- (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];
}
如果任何人有任何洞察到這一問題,這將是非常有益的。
謝謝, 安東尼
感謝您分享此代碼以上傳視頻。附註:您無法自由選擇var categoryStr,它必須是實際的YouTube類別的名稱,否則上傳將失敗。花了我一些時間弄清楚:) – huesforalice