Facebook Graph API: Getting latitude/longitude of a Checkin via Fields API (optimized calling) - facebook

I'd like to know whether there is a way to directly get the latitude/longitude fields via the Facebook Graph API.
The background is that I want to reduce the amount of data which is returned by the Graph API by getting rid of fields which are not of interest for my application.
I know there's something like this working in the Graph API Explorer:
me/?fields=id,checkins.fields(id,place.fields(id,location),created_time)
It returns the following:
{
"id": "12345",
"checkins": {
"data": [
{
"id": "101511234546244",
"place": {
"id": "170048419682121",
"location": {
"street": "",
"city": "Frankfurt",
"state": "",
"country": "Germany",
"zip": "",
"latitude": 50.108641831527,
"longitude": 8.6654729704433
}
},
"created_time": "2012-11-08T08:30:48+0000"
}
]
}
As I don't need the address parts of the location, I'd really like to get rid of them as well. If I try this the follwoing way, it doesn't work:
me?fields=id,checkins.fields(id,place.fields(id,location.fields(latitude,longitude)),created_time)
The result is
{
"id": "12345",
"checkins": {
"data": [
{
"id": "101511234546244",
"place": null,
"created_time": "2012-11-08T08:30:48+0000"
}
]
}
Did somebody have success in doing something similar? If so, I'd be great if you could let me know. Thanks!

According to the API documentation and the Graph API explorer, Subfields are not supported by location so you are unable to extract just latitude and longitude from the location object.

Related

Getting facebook place id from instagram place

I know from the documentation of the instagram API that instagram has facebook locations mapped so you can search and get the location detail from instagram via facebook place id i.e.
https://api.instagram.com/v1/locations/search?facebook_places_id=273471170716&access_token=[ACCESS-TOKEN]
As you can see I am retreiving the location detail via facebook place id.
But in my scenario, what I want is to get facebook place id using instagram id from the instagram location detail. Below is what I mean:
I have got the instagram location id and can get the detail of the place using the following:
https://api.instagram.com/v1/locations/2862169?access_token=[ACCESS-TOKEN]
But the above call only returns the location name and geographic co-ordinates. Whereas I want the Facebook place id of the location as well. Is there any way for me to get the facebook place id from the instagram as well?
I have checked their documentation on Location endpoints (https://instagram.com/developer/endpoints/locations/) and wasn't able to find any relevant information.
The reason why I want that is, I need to get the location detail such as category etc as well which instagram API doesn't provide, so I plan on using this retrieved facebook place id on facebook graph API to retrieve this additional location details.
I think you can only use the Facebook Graph API search for this. Therefore, you can use the output from the Instagram API for latitude, longitude and name to construct a Graph API call which returns you a list of matching Facebook Place Pages.
If the Instagram location id is 788029 for example, the API will return the following JSON:
{
"id": "788029",
"latitude": 48.858844300000001,
"longitude": 2.2943506,
"name": "Eiffel Tower, Paris"
}
So, if you take this result and use the data to construct a Facebook Graph API search url, it will result in something like this:
https://graph.facebook.com/search?q=Eiffel%20Tower,%20Paris&type=place&center=48.858844300000001,2.2943506&distance=100&limit=3&access_token={app_access_token}
You can choose the distance as well as the limit as you desire. If you set limit=1 you will only receive the place which Facebook deems to be the best match. Replace {app_access_token} with an actual App Access Token.
The Facebook response will be something like
{
"data": [
{
"category": "Local business",
"category_list": [
{
"id": "276651312419490",
"name": "Monument"
}
],
"location": {
"street": "",
"city": "Paris",
"state": "",
"country": "France",
"zip": "75007",
"latitude": 48.858385562198,
"longitude": 2.2944861654879,
"located_in": "141184112585566"
},
"name": "Level 2 Eiffel Tower, Paris",
"id": "380503552017025"
},
{
"category": "Local business",
"category_list": [
{
"id": "186825111351005",
"name": "Tourist Attraction"
}
],
"location": {
"street": "",
"city": "Paris",
"state": "",
"country": "France",
"zip": "",
"latitude": 48.858205346341,
"longitude": 2.2944900587791
},
"name": "Eiffel Tower Sommett, Paris, France",
"id": "1458706024363987"
},
{
"category": "Restaurant/cafe",
"category_list": [
{
"id": "168976549819329",
"name": "French Restaurant"
}
],
"location": {
"street": "",
"city": "Paris",
"state": "",
"country": "France",
"zip": "75007",
"latitude": 48.858532957713,
"longitude": 2.2941094631632,
"located_in": "141184112585566"
},
"name": "58 Tour Eiffel (officiel)",
"id": "148894855169991"
}
],
"paging": {
"next": "https://graph.facebook.com/v2.2/search?limit=3&type=place&q=Eiffel Tower, Paris&center=48.858844300000001,2.2943506&distance=100&offset=3&__after_id=enc_AdCYS3bVKOc29JFMrqlsouSZCvBxUTYZC7nHvqDHKAiBNrOs2ehUIaOsJ2wL9TxF9KOfgGmqEPOaLwotDM4pIUqyFf"
}
}
See
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#search
https://instagram.com/developer/endpoints/locations/

Facebook Graph Search Error while searching "Event"

This is embarrassing, but I am at my wits end. While performing a very simple search for "Events" using fb Graph Search, I get the following error:
{
"error": {
"message": "(#200) Must have a valid access_token to access this endpoint",
"type": "OAuthException",
"code": 200
}}
This is the code I execute:
https://graph.facebook.com/search?q=conference&type=event&limit=1&access_token=XXXXXXXXXX|XXXXXXXXXX
It works JUST FINE for any other type of search - with the same access token for example:
https://graph.facebook.com/search?q=conference&type=place&limit=1&access_token=XXXXXXXXXX|XXXXXXXXXX
I get the following result:
{
"data": [
{
"category": "Local business",
"category_list": [
{
"id": "164243073639257",
"name": "Hotel"
}
],
"location": {
"street": "Langelaan 3",
"city": "Noordwijk",
"state": "",
"country": "Netherlands",
"zip": "2211XT",
"latitude": 52.251963727407,
"longitude": 4.4722281054509
},
"name": "NH Conference Centre Leeuwenhorst",
"id": "165032770219308"
}
],
"paging": {
"next": "https://graph.facebook.com/search?limit=1&type=place&access_token=XXXXXXXX|XXXXXXXXX&offset=1&__after_id=165032770219308"
}
}
At this point, I am out of ideas.
Facebook recently changed things in their API, Search was one of those things. You can only do this kind of search on Places and Pages now. To search events, you need an app access token. See this blog post: https://developers.facebook.com/blog/post/2013/04/03/platform-updates--operation-developer-love/
Fixed! I am now able to search for events by using an App Token generated using the new api. Thank everyone for your help

Is it possible to get the country code of a user from Facebook's Graph API?

When i tried to get the current location of a user via FQL, Graph API returned something like this;
{
"data": [
{
"current_location": {
"city": "Izmir",
"state": "Izmir",
"country": "Turkey",
"zip": "",
"id": 107968765903327,
"name": "İzmir, Turkey"
}
}
]
}
Using the Graph ID above, i checked the location information from https://graph.facebook.com/107968765903327 and this time i get more data about the city;
{
"id": "107968765903327",
"name": "\u0130zmir, Turkey",
"link": "http://www.facebook.com/pages/\u0025C4\u0025B0zmir-Turkey/107968765903327",
"likes": 178460,
"category": "City",
"is_published": true,
"is_community_page": true,
"description": "\u003Cp>\u003Cb>Izmir\u003C/b> is a large ...",
"location": {
"latitude": 38.4072,
"longitude": 27.1503
},
"checkins": 9059,
"talking_about_count": 238710
}
But, as you see, there is no chance for the country code with these options. Any other suggestions?
reverse geocode could help
see https://developers.google.com/maps/documentation/geocoding/

How do you retrieve the "Place" field of a Facebook Graph Post object?

I am trying to retrieve the "Place" field of a Facebook Graph Post object from a Facebook friend. After obtaining an access token with the friends_status and read_stream permissions, I request from the Graph API like so:
http://graph.facebook.com/[user_id]_[post_id]
What is returned are some of the fields described in the Graph API docs for Post:
{
"id": "1164358582_2458311174854",
"from": {
"name": "Joe Blo",
"id": "1164358582"
},
"message": "Is pretty bummed today",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/1164358582/posts/2458311174854"
},
{
"name": "Like",
"link": "http://www.facebook.com/1164358582/posts/2458311174854"
}
],
"type": "status",
"application": {
"name": "Facebook for Android",
"id": "350685531721"
},
"created_time": "2011-11-20T03:23:04+0000",
"updated_time": "2011-11-20T12:12:49+0000",
"comments": {
"data": [
{
"id": "1164358582_2458311174852_2962531",
"from": {
"name": "Sue Candy",
"id": "1056617421"
},
"message": "OMG I'm so sorry!!!",
"created_time": "2011-11-20T03:25:06+0000"
}
],
"count": 1
}
}
This is all fine and dandy, except for the fact that when I see this Post within my Facebook stream, it also shows a location accompanying the post:
9 hours ago near El Reno, OK
I expected the El Reno, OK Place object returned as a field within this Post, but I don't see it.
In the Facebook Graph API Explorer, I've tried enabling almost every permission and I am not seeing any difference in the response (no "Place" field returned). Am I going about this incorrectly?
Not 100% sure but I think you can only get the "place" info if it is of type "checkin". I totally get where you are coming from, I wondered about that myself.
https://developers.facebook.com/tools/
Try the Graph API Explorer Tool if you haven't already looked at it.

How to Set Venue for Event using Graph API

When I create events, I've tried adding venue details similar to what it looks like below, but the venue information seems to be ignored. (I'm posting it to /me/events)
The event otherwise gets created successfully. How can I set the venue during the creation process? Do I need to create it afterwards instead? Thanks
{
"owner": {
"name": "David R",
"id": "234234"
},
"name": "sdf",
"description": "tes",
"start_time": "2011-09-11T00:00:00",
"end_time": "2011-09-11T03:00:00",
"location": "sadf",
"venue": {
"street": "weber",
"city": "Waterloo",
"state": "Ontario",
"country": "Canada"
},
"privacy": "SECRET",
"updated_time": "2011-09-10T23:22:23+0000",
"type": "event"
}
get rid of '"venue"{}' and just use city state country etc..
{'name':"neverland",
'city':"los angeles",
'description':"ontherparty",
'location':"sames",
'start_time': "9-12-2011 12:45"
}