I am trying to connect to google trends and parse their response. I have code like this.
String urlstr = "http://www.google.com/trends/fetchComponent?q=seattle&cid=TIMESERIES_GRAPH_0&export=3";
URL url;
String responsestr = null;
try {
url = new URL(urlstr);
//Reader reader = new InputStreamReader(url.openStream(),"UTF-8");
URLConnection connection = url.openConnection();
connection.setRequestProperty("Accept-Charset", "UTF-8");
InputStream response = connection.getInputStream();
Reader reader = new InputStreamReader(response);
}catch(Exception e){}
You can check that the URL is correct by simply copy pasting the url into a browser, however, although my code goes through and connects with google, it returns an error on the side of google saying that it can't process my request. I am doing something wrong in the encoding or the URL or how I am setting up my URLConnection. Any help would be appreciated!
getting the response as below.
Output