2013-03-29 50 views
4

我一直工作了大约10个小时,而我完全失去了100%。我试图简单地询问youtube,比如说“iPad”。然后youtube应该返回搜索结果列表...但我有各种各样的问题。这里是我的代码:如何使用Youtube API(GTLYoutube)在i​​Phone sdk上搜索视频?

 // 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”'。 –

回答

2

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

您可以访问这里:https://code.google.com/apis/console

单击服务,确保YouTube数据API被打开。

2

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

+0

为我工作!谢谢。从Google控制台删除所有软件包ID将其踢入“任何应用程序允许”模式,并开始工作。 –

相关问题