On that note, if you wanted to use the other service I linked above, it just needs 1 extra line to set the httpHeaders with your public API key (when registering free, you get a private and public key for both live and test servers, and its free for up to 100,000 API calls/month). The public key has 'pk' in it:
Code: Select all
set the httpHeaders to "Authorization: " & "prj_live_pk_<your unique key here>"
put url ("https://api.radar.io/v1/geocode/ip") into field 1
The return is a bit different - annoyingly it returns a part of London I'm close to as the 'city' - but on the plus side it gives the icon of the flag (visible when used as an array) and it also returns an HTTP code which may be useful for debugging:
"ugly JSON" wrote:{"meta":{"code":200},"address":{"countryCode":"GB","country":"United Kingdom","countryFlag":"üá¨üáß","state":"England","stateCode":"EN","city":"Pimlico","latitude":51.485,"longitude":-0.1355,"layer":"locality","geometry":{"type":"Point","coordinates":[-0.1355,51.485]}},"proxy":false,"ip":"161.17.0.123"}
If you use FerrusLogic's excellent PhotonJSON library (
https://github.com/Ferruslogic/PhotonJSON), you can make this more readable:
Code: Select all
start using stack "community.ferruslogic.library.photonjson"
put beautifyJSON(field 1) into field 1
Code: Select all
{
{
"meta": {"code": 200},
"address": {
"countryCode": "GB",
"country": "United Kingdom",
"countryFlag": "\u0086\u0087\u0086\u0087",
"state": "England",
"stateCode": "EN",
"city": "Pimlico",
"latitude": 51.485,
"longitude": -0.1355,
"layer": "locality",
"geometry": {"type": "Point", "coordinates": [-0.1355, 51.485]}
},
"proxy": false,
"ip": "161.17.0.123"
}
}