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.
Related
I am running this line of code:
location_list = self.service_mbbi_v1.accounts().locations().list(parent=account_name,readMask='name').execute()
And I get the list of the location IDs but I don't manage to get the Location display name, the display name, not just the ID. I wrote google and told them about my issue and they told me they are looking into it but it has been 2 weeks and no response yet. So just wanted o see if someone else had the same issue and if they fpund a solution or a workaround.
The documentation provides only an example, not a list of possible values:
https://developers.google.com/my-business/reference/businessinformation/rest/v1/accounts.locations/list
And even when I try the example value of the readMask flag I get an error:
[{'#type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'read_mask', 'description': 'Invalid field mask provided'}]}]">
I found this similar question:
Google Business Profile API readMask
The example they provide work for me but I still can't get the display name value.
I thought of using the google place ID I get from the metadata response and see if I can use another API to find the name but it feels they should be a proper 'readMask' string vale for the display name here and it is not 'displayName'..
Has anyone a hint of what can I do?
Thanks a lot
If you are trying to get the business name data, your readMask should be 'title'.
I currently have a working app and I would like to have Rails detect a visitor's location by the IP address and display the city and state on the homepage of my website. For example, it would display "Hello {Name} from City, State".
Visitors do not have to enter anything. I'm aware of things like GeoIP and Geocode. As far as I know about them, they are used to search for locations from IP or vice versa but they require manually inputting the info.
I need it to do it automatically as soon as the user visits my homepage. I have a Post Controller and a home page, and I just want to add some code to my home page's HAML to display the info. I plan to categorize user's posts based on location, which will be automatically filled in (I currently have a location field that user's must enter manually). If you can show me how to do that too, that would be great.
For a live example of what I'm needing, visit weather.com and you'll see your city (and the weather) on the homepage.
Additional info: I'm fairly new to Rails 4 (started 2 weeks ago) so please show me the simplest way and point me to video resources if possible.
Add to the gemfile
gem 'geocoder'
run bundle install and restart your server
Put <%= request.location.city %> in the view you want the city name to appear in.
There are lots of services that provide RESTful JSON APIs which will give you location data based on the IP address, for example: http://www.telize.com/
All you need to do is in your controller, catch the source of the HTTP request (Rack::Request) via request.env['REMOTE_ADDR'] and feed to the Geo API.
One more solution is to use ruby gem for Yandex locator (https://tech.yandex.ru/locator/). Yandex locator is a service that finds mobile devices in a region delineated by a circle. The service returns longitude, latitude and precision. https://github.com/sergey-chechaev/yandex_locator
client = YandexLocator::Client.new(api_key: 'api key', version: '1.0')
result = client.lookup(ip: { address_v4: '178.247.233.3' })
result.position
# => {"altitude"=>0.0, "altitude_precision"=>30.0, "latitude"=>41.00892639160156, "longitude"=>28.96711158752441, "precision"=>100000.0, "type"=>"ip"}
How can I find the location of a specific user's tweet? What are the API methods and techniques that I need to go through to determine the location?
Note: The below assumes that you want to grab multiple tweets and find their locations. If you don't, and you just want a single tweet by it's id, use statuses/show.
It's entirely possible - if the user has enabled location for their tweet. It'll be the value of the coordinates key, which will be null if they haven't.
Let's say you're using the following API method: statuses/user_timeline.
This is a GET request
The resource url is: https://api.twitter.com/1.1/statuses/user_timeline.json
You can specify either the user_id or screen_name as part of the GET parameters, for example: ?screen_name=J7mbo.
In the tweet results, once json_decode() is run on them, one of the keys will look like this:
This is actually the first key, according to the documentation, so you should be able to find it and it's value pretty easily.
Warning
Do not get confused with the location sub-key underneath the User key. This is the location of the user, as per their profile, not the location of any specific tweet. Use the coordinates key for that.
Documentation Link
I am new to the Twitter API and iOS, but reading the documentation I learned to use the "Twitter.framework" in xCode and the "TWRequest" class in specific.
The most obvious way to go would be to make a request to:
GET statuses/public_timeline
However that request does not allow a parameter to specify a latitude and a longitude to get the most recent public tweets within a country. I did find:
GET geo/search
Which allows me to set all kind of cool parameters such as lat, long and granularity, but unfortunately it does not return tweets in the results.
So is it possible? Or a lost cost?
Edit:
So I guess I should be using:
GET search
But the only downfall is that I should give a q (query), a search term, but I am not searching for a specific term. I just like to retrieve the most recent public tweets in a given country. So is there, and should I use, a wildcard?
First make a request to:
GET geo/search
To get the place ID. For The Netherlands the ID is 879d7cfc66c9c290.
Then make a search request to:
GET search
With the query:
q=place:{PLACE_ID}
Example: "q=place:879d7cfc66c9c290"
If you like to get the most recent you can also set a parameter called result_type and set it to recent and that's it. Hope it helps people.
I am having a bit of trouble sifting through the twitter API. I am trying to search for tweets near a certain location and then see their exact (or approximate) geo coordinates. I understand the geo field is deprecated and now we are supposed to use the "place" field. Unfortunately when I use the following url: http://search.twitter.com/search.json?q=&geocode=30.1829,-97.832,10mi I get a bunch of responses with a location that matches the city of the geo coordinates, but geo: is null and there is no place field. Am I stuck with only having an accuracy up to city coordinates, or am I using the wrong search call?
Thanks in advance!
Remember, tweeting with a geo location is an opt-in process. Twitter will supply a feed from the area for all tweeters in that area, but only those who have opted to tweet their coordinates will show up with "geo" info.
Using q=here with your url it did return 1 tweet for me with "geo" info in this form (though likely it will have moved on down the timeline by the time you try...):
"geo":{"coordinates":[-33.9769,18.5080],"type":"Point"}
Every user has a user defined location set in their profile settings. Use this when users don't use geo-encoding.
You can obtain a list of all countries / states by country and do a simple clean-up operation on the dataset.
This gave me what I needed for location data and greatly enriched my output.