2

我正在使用以下代码尝试通过 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 帐户的权限。

身份验证期间使用的范围是:

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

我已经调整/搜索了几个小时,似乎找不到任何关于我得到的错误代码的信息......

4

0 回答 0