2012-05-29 189 views
11

我想從我的iPhone應用程序上傳至YouTube的視頻.. 我已經試過這http://urinieto.com/2010/10/upload-videos-to-youtube-with-iphone-custom-app/ 但最終我得到錯誤 域= com.google.GDataServiceDomain代碼= 400「操作無法完成(com.google.GDataServiceDomain錯誤400.)「UserInfo = 0x4d921f0 {}上傳視頻

任何人都可以幫助我。 Thanx!

我的代碼第一

NSString *devKey = [mDeveloperKeyField text]; 

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

    NSString *username = [mUsernameField text]; 
    NSString *clientID = [mClientIDField text]; 

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

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

    // gather all the metadata needed for the mediaGroup 
    NSString *titleStr = [mTitleField 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:path 
               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]; 
+0

你可以發佈你的代碼嗎? – Zakaria

+0

是的..我正在使用我的谷歌帳號 –

+0

@SurenderRathore:我也面臨同樣的問題......你能幫我嗎? –

回答

1

第一件事,檢查的YouTube API的任何更新它的GData庫,(他們改變了過去的我用他們,並打破了我的應用程序)。

http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html

其次,檢查愚蠢的東西。你所有的頭文件都導入了,一切都結束了,等等?

嘗試設置您的info.plist使用Wi-Fi,我聽說一些新的GData API的外觀可能會解釋您的400錯誤,您的應用可能無法ping通YouTube服務器。