自定义 google 搜索 api 加载资源失败:net::ERR_EMPTY_RESPONSE 401 状态(未授权)

custom google search api failed to load resource: net::ERR_EMPTY_RESPONSE status of 401 (Unauthorized)

I am following the tutorial at this blog for a simple mean app using a google custom search api,我 运行 搜索并在 g运行t 和“Failed to load resource: the server responded with a控制台上的 401(未授权)”状态,后跟“无法加载资源:net::ERR_EMPTY_RESPONSE”。我假设这里还有一些自定义工作要做,例如搜索引擎或密钥,但我不完全确定从哪里开始,因为我对 mean/express/backend.[=18= 还很陌生]

All of the code can be seen here and I can post specific pieces if needed.

我有一个 google acc,API 项目,API 密钥,google 开发者控制台上的自定义搜索引擎,以及通过 google 开发者。控制台,我可以轻松地使用他们发布在 html 页面上的脚本来进行自定义搜索,所以我认为这方面的一切都运行良好。然而,我真的希望平均框架使用这个应用程序来处理调用,这样我就可以在后端学习正确的处理方式。我在 google 开发人员控制台上点击 api,因为它说我每天最多有 100 个请求,我已经使用了其中的 40 个,但是每个请求都有一个客户端错误 (4xx)要求。另一位开发人员朋友告诉我,这并不一定意味着它实际上是客户端。所以我有点迷路了。我会继续修补和搜索,但如果您有任何进一步的想法,我很高兴听到。

I remembered something from an internship where some research brought about some info like this。总而言之,jsonp 可能无法与本地主机的 url 一起使用,因为 1.'Localhost' 是少数几个在含义上动态变化的 DNS 主机名之一,具体取决于查询的时间和地点,这使得潜在的目标脆弱。他建议更改主机名。

还有! 我有一个新的和令人兴奋的拼图。 (我不关心这些密钥,因为这是出于学习目的。我会在需要时生成新密钥)我已经设法在不使用 headers 的情况下直接在 Advanced Rest Client 中调用(我应该使用 headers?) 这个url: https://www.googleapis.com/customsearch/v1?cx=AIzaSyDYPylFKYXm25ehQNEt8ViC30e74U6kbzE&q=asdf&num=10&key=AIzaSyA5lOVg_veudp8iUMc2GkTMnMXPJrjFNrk

我收到了这个object!

{
error: {
errors: [1]
0: {
domain: “usageLimits”
reason: “ipRefererBlocked”
message: “There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.”
extendedHelp: “https://console.developers.google.com”
}-
–
code: 403
message: “There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.”
}-
}

是否有特定的方法来包含我将在 google 开发人员控制台上使用的 uris 和 urls?

我发现很多人通过将 API 设置为允许任何引荐来源网址和任何 ip 来解决这个类似的问题。这并不理想,但有效。