Get country codes of Twitter followers - twitter

How do I get country codes of my Twitter followers using the Twitter API? Or is there any work around to get the same?

From the documentation https://dev.twitter.com/docs/api/1/get/users/show
The response should have a location field, like
"location": "San Francisco, CA",
The data in there is free text, so people can type "London" or a lat/long or even nonsense.
Most people have some geo-data in there.

Related

What are the solutions when geocoding a wrong or incomplete address?

My company gets the addresses the loading hubs for our freights every week. We need to geocode them into coordinates. But often the addresses either are incomplete or contain minor grammar mistakes, so it's impossible to input them for geocoding.
My question : when dealing with a list of wrong or incomplete addresses when geocoding, is there any general solution to solve the issue ?
If there are useful articles or resources about this topic, please let me know.
Thank you.
Geocoding / Autocomplete
According to the Geocoding Addresses Best Practices documentation:
"Geocoding is the process of converting addresses (like a street address) into geographic coordinates (latitude and longitude), which you can use to place markers on a map, or position the map."
"In general, use the Geocoding API when geocoding complete addresses (for example, “48 Pirrama Rd, Pyrmont, NSW, Australia”). Use the Places API Place Autocomplete service when geocoding ambiguous (incomplete) addresses."
The Place Autocomplete service returns place predictions according to your inputs. This would solve your problem of having wrongly spelled addresses.
How to get the coordinates after using Place Autocomplete?
example request for Place Autocomplete would look like this:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Paris&types=geocode&key=YOUR_API_KEY
The Place Autocomplete is able to return the address description together with its place_id. In this sample request, you are able to get "description": "Paris, France" with a "place_id": "ChIJD7fiBh9u5kcRYJSMaMOCCwQ".
Then you can use the Place ID of the predicted location to obtain the coordinates of that place by using Place Details request
You can request it like this:
https://maps.googleapis.com/maps/api/place/details/json?fields=geometry&place_id=ChIJD7fiBh9u5kcRYJSMaMOCCwQ&key=YOUR_API_KEY
We used here the fields=geometry to only return the coordinates of the location and as previously mentioned the Place ID we used is the one we had from the Autocomplete query.
The returned data will be the expected result according to your question. But feel free to comment if you need anything.
To read more about the fields parameter, refer to the Place Details documentation.
I hope this helps!

youtube-api, v3, geolocation information

Although the youtube-api, v3, allows you to make a request for videos that come from a particular area (for example, by specifying the location and the radius), it appears that the resulting information about the videos does not contain location information. That is, you can't get the reported lat/long of the video itself.
A query for a specific location would look like this:
https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&key=[key]&location=37,5%2C-120.5&locationRadius=2km&maxResults=5
Here's the description of the information returned.
https://developers.google.com/youtube/v3/docs/search#top_of_page
So, is that correct? Is there no longer any way to find out the lat/long information of a video that is returned in a query?
OK, I figured this out. The location query will only return the various snippets of information about the videos, that is true. However, you can then look at individual videos in more depth to find their locations. For example:
https://www.googleapis.com/youtube/v3/videos?part=recordingDetails&key=[key]&id=HiFnDoUiaqg
will return recording information including:
"recordingDetails": {
"location": {
"latitude": 37.50973,
"longitude": -120.49805,
"altitude": 0.0
},
So it's a 2-step process. You find the list of videos returned by the location query, and then you look at the detailed information for those videos.

Rails Koala gem - get user's country

I'm using OmniAuth and the Koala gem to add Facebook Connect to my app and i'm trying to get the user's country.
So far I have:
graph = Koala::Facebook::API.new(user.oauth_token)
profile = graph.get_object("me")
profile["location"] gives me the id and name of the city.
I've tried: graph.get_object(city_id) which returns the city object, but I can't find any mention of the city's country in it.
I can also get the country name from the location string: "Kfar Saba, Israel" but that seems like a hack... Any official way to get what i'm looking for? Thanks!
There's the issue that the location data is not always complete for Place pages. I think you'll need to implement the location string parsing as a fallback if the location.country field of the Place page is empty. Be aware that the location string may also contain the location.state, which means that you'll have to use the last token after the split by comma.
Graph API returns no country for the named city:
https://developers.facebook.com/tools/explorer?method=GET&path=114269838585202&version=v2.0
See https://developers.facebook.com/docs/graph-api/reference/v2.0/page#readfields for the Page object structure.

Verify user input location string is a valid geographic location?

I'm accepting a user input which is supposed to be a geographic location. I would like to validate that what the user has entered describes a location--e.g., postal code, airport code, street address, city name, etc.
The obvious answer is to use the Google Geocode API to do a request for the user's input and see if I get any results.) However the geocode ToS forbids this:
...the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited.
Does anyone know of alternatives?
Yahoo also has a geolocation API which has a less-restrictive TOS. By querying for a location, if you receive a non-null result set then you know its a valid place.
# A query for New York...
http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20geo.places%20where%20text='New+York'&format=json
# Results in a response
{"query":{"count":10,"created":"2013-01-11T18:40:32Z","lang":"en-US","results":{"place":[... places ... ] }}}
whereas
# A query for junk
http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20geo.places%20where%20text='kqpo234xk'&format=json
# Results in null
{"query":{"count":0,"created":"2013-01-11T18:39:21Z","lang":"en-US","results":null}}

Yahoo Placefinder API - city returns neighborhood, which it shouldn't

I want to use the Yahoo Placefinder API for user registration for city input (auto suggest). Based on the documentation I can to the following GET request:
http://where.yahooapis.com/geocode?city=falenty&country=poland&appid=yourappid
If you put this in browser, it gives you some XML:
...
<line1/>
<line2>05-090 Falenty</line2>
<line3/>
<line4>Poland</line4>
<house/>
<street/>
<xstreet/>
<unittype/>
<unit/>
<postal>05-090</postal>
<neighborhood>Falenty</neighborhood>
<city>Raszyn</city>
<county>Pruszkow County</county>
...
But I don't want to search by neighborhood if I was searching by city. If there is no city by this name, I don't want to get any results.
Does anybody have any idea if that is possible or do I need to loop through results and exclude those results where the city is not the same as what was sent in the URI? This is not an elegant solution because sometimes it gives me more than 10 results and not even 1 with the city I was searching for.

Resources