如何在iPhone SDK中使用Youtube API(GTLYoutube)搜索视频?

4

我已经工作了大约10个小时,但是完全迷失了。我正在尝试简单地查询Youtube上与"iPad"相关的内容。然后Youtube应该返回一系列搜索结果...但是我遇到了各种各样的问题。以下是我的代码:

     // Create a service object for executing queries
GTLServiceYouTube *service = [[GTLServiceYouTube alloc] init];
// Services which do not require sign-in may need an API key from the
// API Console
service.APIKey = @"AIzaSyD9pvsUtnegJvwv5z5XrBO5vFTBVpErYN8";
// Create a query
GTLQueryYouTube *query = [GTLQueryYouTube queryForSearchListWithPart:@"video"];
query.q = @"hiking boots";
//query.country = @"US";
// Execute the query
GTLServiceTicket *ticket = [service executeQuery:query
                               completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
                                   // This callback block is run when the fetch completes
                                   if (error == nil) {
                                       //I'VE NEVER GOTTEN TO HERE, I ALWAYS GET AN ERROR
                                       }
                                   }else{
                                       NSLog(@"Error: %@", error.description);
                                   }
                               }];

如果我这样做,就会出现以下错误:

    Error Domain=com.google.GTLJSONRPCErrorDomain Code=403 "The operation couldn’t be completed. (Access Not Configured)" UserInfo=0x1edab4c0 {error=Access Not Configured, GTLStructuredError=GTLErrorObject 0x1eda3f80: {message:"Access Not Configured" code:403 data:[1]}, NSLocalizedFailureReason=(Access Not Configured)}

"

我该怎么办?

"

3
这段代码非常有用。我需要使用[GTLQueryYouTube queryForSearchListWithPart:@"snippet"]代替@"video" - Chris Nolet
2个回答

2

对我有用!谢谢。从Google控制台中删除所有捆绑标识符将其置于“允许任何应用程序”模式,并且它开始工作了。 - Chris Nolet

2
“Access Not Configured”错误很可能是因为您尚未在Google API控制台中启用YouTube数据API。
您可以访问此处:https://code.google.com/apis/console 单击“服务”,确保已打开YouTube数据API。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接