使用YouTube api v3.0上传视频失败,出现无法记错的错误代码(目标C)

时间:2013-01-23 12:04:20

标签: objective-c youtube-api

我正在使用以下代码尝试通过v3.0 api从iOS(已安装)应用程序将视频上​​传到YouTube:

...

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);
};

...

在上传完成之前,所有内容似乎都很好,我收到以下错误:

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)}

我认为这可能是授权或我的应用设置的问题;但是,我能够使用相同的凭据成功获取视频类别列表。我还验证了该应用已被授予从我Google帐户的帐户页面访问我的Google帐户的权限。

auth期间使用的范围是:

@"https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.upload"

我一直在调整/搜索几个小时,似乎无法找到任何关于我得到的错误代码......

0 个答案:

没有答案