Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freegeoip API endpoint needs updated #115

Open
kng229 opened this issue Jul 31, 2018 · 3 comments
Open

Freegeoip API endpoint needs updated #115

kng229 opened this issue Jul 31, 2018 · 3 comments

Comments

@kng229
Copy link

kng229 commented Jul 31, 2018

Attempts to use freegeoip() now result in:

Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") : cannot open URL 'http://freegeoip.net/json/155.186.245.217' : HTTP status was '403 Forbidden'

If you navigate to http://freegeoip.net/json/155.186.245.217 in your browser, you receive this prompt:

{
"0": "#################################################################################################################################",
"1": "# #",
"2": "# IMPORTANT - PLEASE UPDATE YOUR API ENDPOINT #",
"3": "# #",
"4": "# This API endpoint is deprecated and has now been shut down. To keep using the freegeoip API, please update your integration #",
"5": "# to use the new ipstack API endpoint, designed as a simple drop-in replacement. #",
"6": "# You will be required to create an account at https://ipstack.com and obtain an API access key. #",
"7": "# #",
"8": "# For more information on how to upgrade please visit our Github Tutorial at: https://github.com/apilayer/freegeoip#readme #",
"9": "# #",
"a": "#################################################################################################################################"
}

@talgalili
Copy link
Owner

talgalili commented Aug 3, 2018 via email

@kng229
Copy link
Author

kng229 commented Aug 3, 2018

I was able to get it to work using

newip <- function (df = NULL)
{
if (is.data.frame(df) == FALSE) {
warning("This function only works with data.frames. Please provide a data.frame.")
}
else {
final <- data.frame()
for (i in 1:nrow(df)) {
url <- paste("http://api.ipstack.com/", c(as.character(df[i,
])), "?access_key=XXXXXXXX&output=json&legacy=1", sep = "")
line <- tryCatch(fromJSON(getURLContent(url)),
error = function(e) e)
country <- ifelse(is.null(line[[3]]), NA, line[[3]])
region <- ifelse(is.null(line[[5]]), NA, line[[5]])
out <- data.frame(country, region)
final <- rbind(final, out)
}
return(final)
}
}

where XXXXX is my access key. I also set it to only pull region and country, which are the variables that I was concerned with but it could easily be generalized

@talgalili
Copy link
Owner

talgalili commented Aug 3, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants