Solved

API Location, separating out information

Posted on 2016-07-24
10
56 Views
Last Modified: 2016-07-26
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!
0
Comment
Question by:Graeme
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 52

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 41728699
hi you can try customize this:
<%


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
    
    if ucase(left(GetTextFromUrl3, 2)) = "OK" then
        CountryLoc=Split(GetTextFromUrl3,";")(3)
    end if
End If
  
Response.Write("GetTextFromUrl = "&GetTextFromUrl3&"<br><br>Location = "&CountryLoc)


%>

Open in new window

0
 

Author Comment

by:Graeme
ID: 41728870
Hi Ryan, just used your code (replaced ACCESSKEY) - not showing any values thou....

GetTextFromUrl =

Location =
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41728879
hi similarly, can you do a response out for oXMLHTTPLoc.responseText and post it here?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:Graeme
ID: 41728880
Response.Write(oXMLHTTPLoc.responseText)

Open in new window


403 Forbidden

nginx

No idea what nginx is, possibly part of the API
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41728883
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?
0
 

Author Comment

by:Graeme
ID: 41728885
That works fine:

OK;;203.161.69.136;AU;Australia
0
 
LVL 52

Assisted Solution

by:Ryan Chong
Ryan Chong earned 500 total points
ID: 41728894
what if you change:

oXMLHTTPLoc.Open "POST",LocationAPI, False
to:
oXMLHTTPLoc.Open "GET",LocationAPI, False
?
0
 

Author Closing Comment

by:Graeme
ID: 41728900
Bingo! works a dream! thanks mate! :)
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41728902
cool man, this seems easier than your another question but at least you got one more issue resolved! cheers
0
 

Author Comment

by:Graeme
ID: 41728904
haha yeah totally! definately some curly questions! :)
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question