Note that there are some explanatory texts on larger screens.

plurals
  1. POHttpWebResponse Times out on Google Places API call
    primarykey
    data
    text
    <p>I am working on an app to iterate through a list of zip codes and business types that will then create a call to the Google Places API (Text Search) via a url that I construct for those parameters.</p> <p>The url will look something like this </p> <p><a href="https://maps.googleapis.com/maps/api/place/textsearch/json?key=MY_API_KEY_HERE&amp;sensor=false&amp;query=57783+dentist" rel="nofollow">https://maps.googleapis.com/maps/api/place/textsearch/json?key=MY_API_KEY_HERE&amp;sensor=false&amp;query=57783+dentist</a></p> <p>The function below is called for each of these requests:</p> <pre><code> private static StreamReader MakeWebRequest(string sURL) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sURL); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader objReader = new StreamReader(responseStream); return objReader; } </code></pre> <p>The problem I am experiencing is that, after 3 to 5 iterations, the response object times out (System.Net.WebException = "The operation has timed out"). My first thought was that the requests were being sent to quickly, so I inserted a Sleep(2000) in the loop, but this seems to have no effect. I have checked the urls that are failing and pasted them into a browser and they <strong>do</strong> return the proper data.</p> <p>As I understand it, the only limitation to calls on this api are the 1000 per day I get with an unverified account. What am I missing?</p> <p>EDIT: Here is the rest of the program block:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO; using System.Web; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using GooglePlacesJSONGenerator.Models; namespace GooglePlacesJSONGenerator { class Program { static void Main(string[] args) { //set up a list of zips List&lt;string&gt; zipcodeList = new List&lt;string&gt;(); zipcodeList.Add("57754"); zipcodeList.Add("57783"); zipcodeList.Add("57785"); //setup a list of business types List&lt;string&gt; businessTypeList = new List&lt;string&gt;(); businessTypeList.Add("restaurants"); businessTypeList.Add("dentist"); businessTypeList.Add("gym"); //main data set GooglePlaceDataSet places = new GooglePlaceDataSet(); //base url string urlBase = "https://maps.googleapis.com/maps/api/place/textsearch/json?key=MY_API_KEY_HERE&amp;sensor=false&amp;query="; string nextUrlBase = urlBase + "&amp;pagetoken="; Stream objStream; //loop on zip codes foreach (string zip in zipcodeList) { Console.WriteLine("looping on zip " + zip); //loop on business type foreach (string type in businessTypeList) { Console.WriteLine("loop on type " + type); string sURL; string query = HttpUtility.UrlEncode(zip + " " + type); sURL = urlBase + query; Console.WriteLine("Query String: " + query); while (sURL != "") { Console.WriteLine("Our URL: " + sURL); Console.WriteLine(""); StreamReader objReader = MakeWebRequest(sURL); JsonTextReader reader = new JsonTextReader(objReader); JsonSerializer se = new JsonSerializer(); string parsedData = se.Deserialize(reader).ToString(); GooglePlaceDataSet gSet = JsonConvert.DeserializeObject&lt;GooglePlaceDataSet&gt;(parsedData); foreach (GooglePlaceData place in gSet.results) { places.results.Add(place); } if (gSet.next_page_token != null) sURL = nextUrlBase + gSet.next_page_token; else sURL = ""; System.Threading.Thread.Sleep(2000); } } } Console.ReadLine(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload