{"id":7238,"date":"2014-06-02T05:27:41","date_gmt":"2014-06-02T05:27:41","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/06\/02\/jsoup-returning-an-error-400-on-google-maps-api-collection-of-common-programming-errors\/"},"modified":"2014-06-02T05:27:41","modified_gmt":"2014-06-02T05:27:41","slug":"jsoup-returning-an-error-400-on-google-maps-api-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/06\/02\/jsoup-returning-an-error-400-on-google-maps-api-collection-of-common-programming-errors\/","title":{"rendered":"Jsoup returning an error 400 on Google Maps API-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m working on a project that requires me to find the coordinates of some shops on Google Maps. I already have the address of each shop.<\/p>\n<p>I have played a little with the Google Geocoding APIs and I think they are what I need: all my code needs to do is connect to the DBMS, retrieve item_id and address, generate a valid URL for the geocoding API and process the JSON data it will get.<\/p>\n<p>I don&#8217;t understand why, but the URL I generate works in my browsers (Chrome 23 &amp; latest Safari, OS X) but won&#8217;t work in Jsoup. I have looked at the source of the page in Chrome, and it looks like it is perfectly valid HTML. So what&#8217;s Jsoup doing wrong?<\/p>\n<p>Code snippet (runnable, will give you the same exception I get):<\/p>\n<pre><code>import java.io.IOException;\nimport org.jsoup.Jsoup;\nimport org.jsoup.nodes.Document;\n\npublic class RandomClass {\n     public static void main(String args[]) {\n     Document doc = null;\n     try {\n        String url = \"http:\/\/maps.googleapis.com\/maps\/api\/geocode\/json?address=0+164+W+75th+St,+New%20York,+NY+10024&amp;sensor=false\";\n\n        String ua = \"Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit\/537.17 (KHTML, like Gecko) Chrome\/24.0.1312.56 Safari\/537.17\";\n        doc = Jsoup.connect(url).timeout(60 * 1000).userAgent(ua).get();\n    } catch (IOException e) {\n        e.printStackTrace();\n    }\n}\n<\/code><\/pre>\n<p>}<\/p>\n<p>throws<\/p>\n<pre><code>org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text\/*, application\/xml, or application\/xhtml+xml. Mimetype=application\/json; charset=UTF-8, URL=http:\/\/maps.googleapis.com\/maps\/api\/geocode\/json?address=164+W+75th+St,+New%20York,+NY+10024&amp;sensor=false\nat org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:436)\nat org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:393)\nat org.jsoup.helper.HttpConnection.execute(HttpConnection.java:159)\nat org.jsoup.helper.HttpConnection.get(HttpConnection.java:148)\nat asdru.RandomClass.main(RandomClass.java:16)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m working on a project that requires me to find the coordinates of some shops on Google Maps. I already have the address of each shop. I have played a little with the Google Geocoding APIs and I think they are what I need: all my code needs to do is connect to the DBMS, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7238","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7238"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7238\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}