Google自定义search:iOS中有403错误
谷歌自定义search从我的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." } }
下面的步骤是否有缺陷? 我想build立特定于iOS应用程序的工作CSE设置过程。 在每一步的截图将有望帮助,而不是混淆!
-
通过https://www.google.com/cse/创build自定义search引擎(CSE)
-
从设置 – >基本,获取search引擎ID。
-
在https://developers.google.com/apis-explorer/#p/customsearch/v1/search.cse.list上testingCSE
- 在步骤2中将“q”设置为search引擎ID的任何testing查询条件(“foo bar”)和“cx”。
- 按“执行”并接收您的search结果。 他们工作。 谷歌也提供了这个url,我们将在第8步在Xcode中重复使用。
-
要使自己成为ID和结算用途的关键,请通过以下url创build新项目: https://console.developers.google.com/
-
在API和身份validation – > API – >启用“自定义searchAPI”。 没有其他的API被启用。
-
在API&auth – > Credentials下 – >创build一个新的iOS密钥。 注意:我也尝试了浏览器键,search结果返回“错误400:无效值”。 由于我在iOS上,所以我返回了iOS键,错误似乎不那么严重。
-
从Xcode中添加此密钥标识符。
-
在Xcode中,在步骤3中向您的GET请求发送URL。用步骤6-7中的凭据replace{YOUR_API_KEY}。
NSData *响应包含上面显示的错误403。 感谢有什么不对的想法!
它缺less标题字段X-Ios-Bundle-Identifier 。
NSString *bundleID = @"com.yourCompany.yourApp"; //...define request as above [request setHTTPMethod:@"GET"]; [request setValue:bundleID forHTTPHeaderField:@"X-Ios-Bundle-Identifier"];