2

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...

  • Are you perhaps running into the same issue as http://stackoverflow.com/questions/14453505/youtube-data-api-v3-video-upload-403-forbidden-youtubesignuprequired – Jeff Posnick Jan 24 '13 at 03:45
  • Same is the case with me, Please tell if u figure out the solution for it. – Ravi_Parmar Jul 19 '13 at 05:53
  • Hi, Found out the problem, its with your "auth" parameters. in this line service.authorizer = auth; are you fetching any authentication data and storing in "auth" parameter before assigning it to service.authorizer? – Ravi_Parmar Jul 19 '13 at 06:14
  • @user2003742: please share what are you passing auth of service.authorizer = auth; I am facing an error in youtube video upload – Abdul Rauf Feb 15 '16 at 07:57

0 Answers0