PHP cURL to Google Civic API
Well, this stumped me for like an hour.
The Google Civic Information API is a handy way to grab voting and elected official information. The current way I do that on GeoPortal is to enter some representative information locally and update it when somebody emails me in ALL CAPS. That is not a good way.
But the Google Civics API’s representative service (oddly) only does POST, and POST doesn’t do JSONP, necessitating a proxy. And to further complicate things, it isn’t a straight-forward cURL operation - you have to send the POST argument as JSON and not the default x-form or you’ll get an error message. So, do this:
1 | // The only arguments are "address" and "callback" (the latter optional for JSONP) |
And then a little jQuery to eat it.
1 | $.ajax({ |