Link to home
Start Free TrialLog in
Avatar of Graeme McGilvray
Graeme McGilvrayFlag for Australia

asked on

API Location, separating out information

Hi All, I have recently learnt a little about APIs and how awesome they are (using a currency API)

Now I would like to use a GeoLocation API - IPInfoDB

API Link: http://api.ipinfodb.com/v3/ip-country/?key=ACCESSKEY&ip=IPADDRESS

API Output
OK;;74.125.45.100;US;United States

Open in new window


This is what I got so far (copying from the Currency API):
Dim oXMLHTTPLoc

Set oXMLHTTPLoc=CreateObject("MSXML2.ServerXMLHTTP")

LocationAPI="http://api.ipinfodb.com/v3/ip-country/?key=ACCESSKEY&ip="&Request.ServerVariables("REMOTE_ADDR")

oXMLHTTPLoc.Open "POST",LocationAPI, False
oXMLHTTPLoc.Send

If oXMLHTTPLoc.Status = 200 Then
    GetTextFromUrl3 = oXMLHTTPLoc.responseText
    Arr1 = Split(GetTextFromUrl3, "OK")
    Arr2 = Split(Arr1(1), ";")
    Arr3 = Split(Arr2(1), " ")
    CountryLoc=Arr3(0)
End If
  
Response.Write("GetTextFromUrl = "&GetTextFromUrl3&"<br><br>Location = "&CountryLoc)

Open in new window


The End result that all I would like is: the 2 letter country Code
eg:
AU
US
GB
etc

Thanks in advance!
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Graeme McGilvray

ASKER

Hi Ryan, just used your code (replaced ACCESSKEY) - not showing any values thou....

GetTextFromUrl =

Location =
hi similarly, can you do a response out for oXMLHTTPLoc.responseText and post it here?
Response.Write(oXMLHTTPLoc.responseText)

Open in new window


403 Forbidden

nginx

No idea what nginx is, possibly part of the API
it means the request to the API seems invalid.

can you see what's the value of LocationAPI, and copy and paste it into your browser, see if got any error there?
That works fine:

OK;;203.161.69.136;AU;Australia
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Bingo! works a dream! thanks mate! :)
cool man, this seems easier than your another question but at least you got one more issue resolved! cheers
haha yeah totally! definately some curly questions! :)