Search code examples
angularjsnode.jsexpressmean-stackgoogle-custom-search

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, and I run a search and get a null returned on grunt and “Failed to load resource: the server responded with a status of 401 (Unauthorized)” on the console followed by “failed to load resource: net::ERR_EMPTY_RESPONSE”. I assume there is a tad bit more custom work to be done here with the likes of the search engine or keys, but I’m not entirely sure where to start as I am very new to mean/express/backend.

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

I have a google acc, API project, API key, custom search engine on the google developer console, and cse id through the google dev. console and I can easily use their script posted on the html page to do custom searches so I think everything on that end is working fine. I however am really wanting the mean framework to handle the call using this app so that I can learn the proper dealings in the backend. I am hitting the api on the google developers console as it says that I have a max of 100 request per day and I have used 40 of them, but there was a client error(4xx) on every request. I am told from another developer friend that this doesn't necessarily mean it is in fact the client side. So I am kinda lost. I’ll continue to tinker and search, but if you have any further ideas I am happy to hear.

I remembered something from an internship where some research brought about some info like this. To summarize it says that it is possible that jsonp may not work with a url of localhost because 1.’Localhost’ is one of few DNS hostnames that are dynamic in meaning depending on when and where it’s queried, making the potential targets vulnerable. and he recommends changing the hostname.

Also! I have a new and exciting piece to the puzzle. (I don't care about these keys as this is for learning purposes. I'll generate new one when I need to) I have managed to call directly in Advanced Rest Client without the use of headers(should i be using headers?) this url: https://www.googleapis.com/customsearch/v1?cx=AIzaSyDYPylFKYXm25ehQNEt8ViC30e74U6kbzE&q=asdf&num=10&key=AIzaSyA5lOVg_veudp8iUMc2GkTMnMXPJrjFNrk

and I received this object back!

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

Is there a specific way to include the uris and urls that I’ll be working with on the google developer console?


Solution

  • I find that many people fix this similar issue by setting the APIs to allow any referrer and any ip. This isn't ideal, but works.