谷歌自定义搜索:iOS中的403错误 [英] Google Custom Search: 403 error in iOS

查看:220
本文介绍了谷歌自定义搜索:iOS中的403错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌自定义搜索从我的iPhone 7.1应用程序返回这个403错误。这是在模拟器中运行时的响应:

  {
error:{
errors :[
{
domain:usageLimits,
reason:accessNotConfigured,
message:Access Not Configured。Please use Google Developers Console为您的项目激活API。
}
],
code:403,
message:访问未配置,请使用Google Developers Console为您的项目激活API。
}
}

在下面的步骤中是否存在缺陷?我想建立特定于iOS应用程序的工作CSE设置过程。每一步的屏幕截图都会有帮助,而不会混淆!


  1. 创建一个自定义搜索引擎(CSE)




    • 设置q 到步骤2中的搜索引擎ID的任何测试查询条件(foo bar)和cx。
    • 按执行并接收您的搜索结果。他们工作。 Google也提供了这个网址,我们将在第8步中在Xcode中重复使用该网址。


  2. 为了让自己成为ID和帐单用途的关键,请在 https://console.developers.google.com/


  3. 在API& auth - > API - >启用自定义搜索API。没有其他API被启用。


  4. 在API& auth - > Credentials - >创建一个新的iOS密钥。

    注意:我也尝试了一个浏览器键并返回搜索结果错误400:无效值。我在iOS上返回到iOS密钥,并且错误似乎不那么严重。

  5. 添加到此密钥您的Xcode包标识符。


  6. 在Xcode中,在步骤3中对URL进行GET请求。在步骤6-7中用您的凭据中的密钥替换{YOUR_API_KEY}。




< NSData *响应包含上面显示的错误403。感谢您对有什么问题的任何想法! X-Ios-Bundle-Identifier

  NSString * bundleID = @com.yourCompany.yourApp; 
//...define请求如上
[request setHTTPMethod:@GET];
[request setValue:bundleID forHTTPHeaderField:@X-Ios-Bundle-Identifier];


Google Custom Search is returning this 403 error from my iPhone 7.1 app. This is the response when run in the simulator:

{
 "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."
 }
}

Is there a flaw in the steps below? I’d like to establish a working CSE setup process specific to iOS apps. The screenshots at each step will hopefully help and not confuse!

  1. Create a Custom Search Engine (CSE) at https://www.google.com/cse/

  2. From Setup -> Basics, get the Search engine ID.

  3. Test the CSE at https://developers.google.com/apis-explorer/#p/customsearch/v1/search.cse.list

    • Set "q" to any test query terms ("foo bar") and "cx" to the Search engine ID in step 2.
    • Press "Execute" and receive your search results. They work. Google also provides this URL which we'll re-use in Xcode in step 8.
  4. To get ourselves a key for ID and billing purposes, create a new project at https://console.developers.google.com/

  5. Under APIs & auth -> APIs -> Enable "Custom Search API." No other APIs are enabled.

  6. Under APIs & auth -> Credentials -> Create a new iOS key. Note: I also tried a browser key and the search result returned "Error 400: Invalid Value." I returned to the iOS key since I'm on iOS and the error seemed less severe.

  7. Add to this key your bundle identifier from Xcode.

  8. In Xcode make your GET request to the URL in step 3. Replace {YOUR_API_KEY} with the key from your credentials in steps 6-7.

NSData *response contains the error 403 shown above. Thanks for any thoughts on what's wrong!

解决方案

It was missing the header field 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错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆