3

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/[email protected]/uploads?upload_id=heregoesidiremoved) failedWithStatus:400 data:GDataInvalidRequestUriExceptionException 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!

1
  • same is the case with my code. if you have working demo of upload video to youtube please share it with me. thnks. my id is [email protected] Commented Jul 8, 2013 at 14:11

1 Answer 1

10

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];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.