2011-11-29 73 views
0

我有一個小應用程序,我在其中使用gdata將視頻上傳到YouTube。每次嘗試時,都會收到以下錯誤信息:「serviceBase:objectFetcher:failedWithStatus:400 data:GData InvalidRequestUriException缺少或無效的用戶名。」Gdata youtube upload failedWithStatus:400

我試過使用我的YouTube管家,或者我的Gmail管家,沒有工作。任何幫助,將不勝感激。

這裏是代碼: 「無效的請求URI或頭,或不支持非標準參數」

NSString *devKey = DEVELOPER_KEY; 

GDataServiceGoogleYouTube *service = [self youTubeService]; 
[service setYouTubeDeveloperKey:devKey]; 

NSString *username = @"[email protected]"; 
NSString *clientID = CLIENT_ID; 

NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username 
                 clientID:clientID]; 

// load the file data 

NSString *videoPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/output.mp4"]; 

// NSString *path = [[NSBundle mainBundle] pathForResource:@"YouTubeTest" ofType:@"m4v"]; 
NSData *data = [NSData dataWithContentsOfFile:videoPath]; 
NSString *filename = [videoPath lastPathComponent]; 

// gather all the metadata needed for the mediaGroup 
NSString *titleStr = [titleTextField text]; 
GDataMediaTitle *title = [GDataMediaTitle textConstructWithString:titleStr]; 

NSString *categoryStr = [mCategoryField text]; 
GDataMediaCategory *category = [GDataMediaCategory mediaCategoryWithString:categoryStr]; 
[category setScheme:kGDataSchemeYouTubeCategory]; 

NSString *descStr = [mDescriptionField text]; 
GDataMediaDescription *desc = [GDataMediaDescription textConstructWithString:descStr]; 

NSString *keywordsStr = [mKeywordsField text]; 
GDataMediaKeywords *keywords = [GDataMediaKeywords keywordsWithString:keywordsStr]; 

BOOL isPrivate = mIsPrivate; 

GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup]; 
[mediaGroup setMediaTitle:title]; 
[mediaGroup setMediaDescription:desc]; 
[mediaGroup addMediaCategory:category]; 
[mediaGroup setMediaKeywords:keywords]; 
[mediaGroup setIsPrivate:isPrivate]; 


NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:videoPath defaultMIMEType:@"video/mp4"]; 

// create the upload entry with the mediaGroup and the file data 
GDataEntryYouTubeUpload *entry; 

NSLog(@"%@", mimeType); 

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]; 

}

回答

0

錯誤代碼400是一個壞的請求這基本上意味着你錯誤地格式化了你的請求。 HTTP Status Codes鏈接來解釋所有的錯誤代碼。

你能發佈你用來上傳視頻的代碼嗎?

編輯: 你可以上傳使用YouTube Sample

如果這工作正常,它會證明你devkey工作正常。這也將表明,它是在這些線路上的問題:

NSString *username = @"[email protected]"; 
NSString *clientID = CLIENT_ID; 

NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username 
                clientID:clientID]; 

NSString *videoPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/output.mp4"]; 

同樣地,如果樣品的YouTube樣品工作,那麼問題要麼

  1. 客戶端尚未驗證您的devkey。 或
  2. videoPath不是正確的位置。
+0

抱歉,延遲...我無法上傳Youtube樣本...同樣的錯誤。 –