I am using the following code in an attempt to upload a video to YouTube from an iOS (installed) application via the v3.0 api:
...
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"test" ofType:@"MOV"];
NSFileHandle *handle = [NSFileHandle fileHandleForReadingAtPath:path];
if (!handle)
{
NSLog(@"Failed to open file for reading");
return;
}
GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
service.authorizer = auth;
GTLUploadParameters *params = [GTLUploadParameters uploadParametersWithFileHandle:handle MIMEType:@"application/octet-stream"];
GTLYouTubeVideoSnippet *snippet = [GTLYouTubeVideoSnippet object];
snippet.title = @"Test title";
snippet.descriptionProperty = @"Test description";
snippet.tags = @[ @"TestOne", @"TestTwo" ];
snippet.categoryId = @"17";
GTLYouTubeVideoStatus *status = [GTLYouTubeVideoStatus object];
status.privacyStatus = @"private";
GTLYouTubeVideo *video = [GTLYouTubeVideo object];
video.snippet = snippet;
video.status = status;
GTLQueryYouTube *query = [GTLQueryYouTube queryForVideosInsertWithObject:video part:@"snippet,status" uploadParameters:params];
// Perform the upload
GTLServiceTicket *ticket = [service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error)
{
if (error)
{
NSLog(@"ERROR: %@", error);
return;
}
NSLog(@"SUCCESS! %@; %@;", ticket, object);
}];
ticket.uploadProgressBlock = ^(GTLServiceTicket *ticket, unsigned long long numberOfBytesRead, unsigned long long dataLength)
{
NSLog(@"%lld / %lld", numberOfBytesRead, dataLength);
};
...
All appears to be well until the upload finishes and I receive the following error:
Error Domain=com.google.GTLJSONRPCErrorDomain Code=-32602 "The operation couldn’t be completed. (Forbidden)" UserInfo=0x936ed70 {error=Forbidden, GTLStructuredError=GTLErrorObject 0x936e7f0: {message:"Forbidden" code:-32602 data:[1]}, NSLocalizedFailureReason=(Forbidden)}
I thought this may be an issue with authorization or my app settings; however, I am able to successfully fetch a video category list with the same credentials. I also verified that the app has been granted access to my Google account from my Google account's account page.
The scope used during auth is:
@"https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.upload"
I've been tweaking/searching for a few hours and can't seem to find anything about the error code I'm getting...