2011-06-23 75 views
1

我試圖使用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]; 
} 

如果任何人有任何洞察到這一問題,這將是非常有益的。

謝謝, 安東尼

+0

感謝您分享此代碼以上傳視頻。附註:您無法自由選擇var categoryStr,它必須是實際的YouTube類別的名稱,否則上傳將失敗。花了我一些時間弄清楚:) – huesforalice

回答

2

該信息由GDataServiceBase.m。它表明類GTMHTTPUploadFetcher沒有鏈接到你的應用程序。

類可能由於類文件不被鏈接在調試或釋放構建目標,或由於預處理器定義GDATA_INCLUDE_YOUTUBE_SERVICE未被設置,如在http://code.google.com/p/gdata-objectivec-client/wiki/BuildingTheLibrary

+1

我在哪裏可以找到GTMHTTPUploadFetcher文件? –

+0

是的,我在哪裏可以找到GTMHTTPUploadFetcher?如果任何人有工作演示項目並且可以與我分享,那將會非常有幫助。我的ID是[email protected]。 –

0

下「刪除不需要的代碼」中描述的缺是的,這似乎是一個鏈接問題。我按照該鏈接上的說明直接編譯到我的代碼中,並刪除了我不需要的類,例如googledocs。一旦我這樣做,一切都很好,我可以上傳。

感謝您的幫助。