I'm trying to post video to youtube from inside of my iPhone application using the GData API. Here is the code I'm using:
GDataServiceGoogleYouTube* service = [self youTubeService];
[service setYouTubeDeveloperKey:youtubeAppKey];
NSString *username = service.username;
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username];
NSData *data = [NSData dataWithContentsOfFile:self.videoPath];
NSString *filename = @"My Cool Video";
NSString *titleStr = @"Title";
GDataMediaTitle *mediaTitle = [GDataMediaTitle textConstructWithString:titleStr];
NSString *categoryStr = @"Comedy";
GDataMediaCategory *mediaCategory = [GDataMediaCategory mediaCategoryWithString:categoryStr];
[mediaCategory setScheme:kGDataSchemeYouTubeCategory];
NSString *descStr = @"Description";
GDataMediaDescription *mediaDesc = [GDataMediaDescription textConstructWithString:descStr];
NSString *keywordsStr = @"iOS";
GDataMediaKeywords *mediaKeywords = [GDataMediaKeywords keywordsWithString:keywordsStr];
GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];
[mediaGroup setMediaTitle:mediaTitle];
[mediaGroup setMediaDescription:mediaDesc];
[mediaGroup addMediaCategory:mediaCategory];
[mediaGroup setMediaKeywords:mediaKeywords];
[mediaGroup setIsPrivate:isPrivate];
NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:self.videoPath
defaultMIMEType:@"video/mp4"];
GDataEntryYouTubeUpload *entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup
data:data
MIMEType:mimeType
slug:filename];
GDataServiceTicket *ticket = [service fetchEntryByInsertingEntry:entry
forFeedURL:url
delegate:self
didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)];
[self setUploadTicket:ticket];
And I'm having this response:
serviceBase: objectFetcher:GTMHTTPUploadFetcher 0x48af0a0 (https://uploads.gdata.youtube.com/resumable/feeds/api/users/myCoolMail@gmail.com/uploads?upload_id=heregoesidiremoved) failedWithStatus:400 data:GDataInvalidRequestUriException
Exception message unavailable
I've tried Google sample code and had the same result. I used device and Simulator (5.0). I've tried prepared video as long as the recorded from iPhone one. I created the Project in the google API section and got an application key.
Please, help me find the solution of the problem!
The problem was here:
NSString *username = service.username;
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username];
Don't know why is that, but I've changed the userID from "username" to kGDataServiceDefaultUser and the thing started working. So simple and so odd, but it did the trick.
Correct code:
NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:kGDataServiceDefaultUser];