Solved

API Location, separating out information

Posted on 2016-07-24
10
53 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question about ASP Including Files 6 66
Multiflying 2 Input Text On a Table 7 35
calculate days away 11 61
Diff of the day 2 42
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…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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