如何使用Youtube API(GTLYoutube)在i​​Phone sdk上搜索视频?

时间:2013-03-29 11:30:27

标签: iphone ios objective-c youtube-api google-oauth

我已经工作了大约10个小时,我完全,100%,失去了。我试图简单地查询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)}

我该怎么办?

2 个答案:

答案 0 :(得分:2)

“未配置访问”错误可能是因为您尚未在Google API控制台中启用Youtube Data API。

您可以在此处访问:https://code.google.com/apis/console

点击“服务”,确保已打开Youtube Data API。

答案 1 :(得分:2)

有一个已知的谷歌问题(https://code.google.com/p/gdata-issues/issues/detail?id=5770)使得即使你打开了正确的API它仍然会失败,旁路就是从谷歌控制台中删除该项目的bundleID。 / p>