ios - Google 自定义搜索 API 返回访问未配置(iOS 应用程序)

标签 ios objective-c google-api google-custom-search

通读了所有类似的帖子,但找不到解决方案。

NSURL连接:

<NSURLConnection: 0x178004020> { request: <NSURLRequest: 0x178003ff0> { URL: https://www.googleapis.com/customsearch/v1?key=[API_KEY_SPECIFIC_TO_IOS_BUNDLE_ID]&cx=[SEARCH_ENGINE_ID_FOR_CUSTOM_SEARCH_ENGINE]&q=[SEARCH_STRING] } }

响应:

{
    error =     {
        code = 403;
        errors =         (
                        {
                domain = usageLimits;
                message = "Access Not Configured. Please use Google Developers Console to activate the API for your project.";
                reason = accessNotConfigured;
            }
        );
        message = "Access Not Configured. Please use Google Developers Console to activate the API for your project.";
    };
}

我前往 Google Developers Console 并为我的项目探索了自定义搜索 API。它对应于这个网址:

https://console.developers.google.com/project/[PROJECT ID]/apiui/api/customsearch/method/search.cse.list

它成功运行并显示了这个请求(以及正确的结果):

GET https://www.googleapis.com/customsearch/v1?q=[SEARCH_STRING]&cx=[SEARCH_ENGINE_ID_FOR_CUSTOM_SEARCH_ENGINE]&key={YOUR_API_KEY}

X-JavaScript-User-Agent:  Google APIs Explorer

所以我从成功中得出结论:

  1. [SEARCH_ENGINE_ID_FOR_CUSTOM_SEARCH_ENGINE] 值正确
  2. [SEARCH_ENGINE_ID_FOR_CUSTOM_SEARCH_ENGINE] 值与我的项目相关联,因为我从我的项目中“探索”了它

我确认自定义搜索 API 确实打开了

我还在该项目下方的 API 访问页面上验证了我使用的是简单 API 访问部分中列出的正确 API key 和 iOS 应用程序(包 ID)。

我不确定从这里到哪里去解决这个问题并让它工作。

任何帮助将不胜感激!

最佳答案

仔细检查您的 Google Developers 控制台是否显示为以下屏幕(对于您自己的模块,我的是谷歌地图)。

enter image description here

enter image description here

如果您确定开发人员控制台端的一切都正确,但您仍然看到错误,请从控制台中删除它并创建一个新的,然后重试。是的,这很奇怪,但我之前遇到过类似的问题,我通过删除并重新创建解决了它。

关于ios - Google 自定义搜索 API 返回访问未配置(iOS 应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23463449/

相关文章:

objective-c - 有没有检查 UIViewController 是否出现的好方法?

c# - 如何使用 C# 和 Sheet Api 访问和插入数据到 Google Spread Sheet?

python - 如何通过文件 ID 查询 google drive API?

email - Gmail 发送名称错误的电子邮件

ios - 有没有资源可以让我们学习如何将不使用 Storyboard的程序修改为使用 Storyboard

ios - 捕获 NSMutableArray 中的默认排序?

ios - Objective C Google Maps API 公钥函数

php - 推送通知适用于开发,而不是生产

ios - 适用于 iOS 的 Firebase,GoogleService-Info.plist 属性 "IS_ANALYTICS_ENABLED"设置为 "NO"

ios - 预期标识符或 ´(´ 括号错误 (?)