Google 自定义搜索从我的 iPhone 7.1 应用返回这个 403 错误。这是在模拟器中运行时的响应:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
}
],
"code": 403,
"message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
}
}
下面的步骤有错误吗?我想建立一个特定于 iOS 应用程序的有效 CSE 设置过程。希望每一步的屏幕截图都能有所帮助,不会造成混淆!
在 https://www.google.com/cse/ 创建自定义搜索引擎 (CSE)
从设置 -> 基础,获取搜索引擎 ID。
在 https://developers.google.com/apis-explorer/#p/customsearch/v1/search.cse.list 测试 CSE
- 将“q”设置为任何测试查询词(“foo bar”),将“cx”设置为第 2 步中的搜索引擎 ID。
- 按“执行”并接收您的搜索结果。他们工作。 Google 还提供了这个 URL,我们将在第 8 步的 Xcode 中重新使用它。
要为我们自己获取用于 ID 和计费目的的 key ,请在 https://console.developers.google.com/ 创建一个新项目
在 API 和授权下 -> API -> 启用“自定义搜索 API”。没有启用其他 API。
在 APIs & auth -> Credentials -> 创建一个新的 iOS key 。 注意:我还尝试了浏览器键,搜索结果返回“错误 400:无效值”。因为我在 iOS 上,所以我返回了 iOS key ,错误似乎不那么严重。
将来自 Xcode 的包标识符添加到此 key 。
在 Xcode 中向第 3 步中的 URL 发出 GET 请求。将 {YOUR_API_KEY} 替换为第 6-7 步中您凭据中的 key 。
NSData *response 包含上面显示的错误 403。感谢您对问题的任何想法!
最佳答案
它缺少 header 字段 X-Ios-Bundle-Identifier。
NSString *bundleID = @"com.yourCompany.yourApp";
//...define request as above
[request setHTTPMethod:@"GET"];
[request setValue:bundleID forHTTPHeaderField:@"X-Ios-Bundle-Identifier"];
关于ios - 谷歌自定义搜索 : 403 error in iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24212412/