How to get location info from Facebook photo object? - facebook

I have a question about Facebook Graph API.
Here are two FB photo objects with geo location, in the first photo, the geo location is "Rio Douro", and the geo location in the second photo is "Santa Clara, Portugal 附近".
I know I can use graph API like "{photo-id}?fields=place" to get the location info (Rio Douro) from the first photo.
http://i.stack.imgur.com/drnMQ.jpg
But how can I get the location info from the second photo?
"{photo-id}?fields=place" won't return anything....:(
http://i.stack.imgur.com/8VWsP.jpg
Thanks in advance for any help!

You cannot, that information is not part of the Photo's details but is general information attached to the post; it's not retrievable via the API

Related

Get photo from post using Facebook graph API

I am attempting to display the latest post from a public Facebook page on a website using the graph API.
Using the following URL, I am able to get the latest posts data:
https://graph.facebook.com/MYPAGENAME/posts?access_token=MYACCESSTOKEN
Which returns:
{
"data": [
{
"story": "MYPAGENAME added a new photo.",
"created_time": "2017-08-20T19:00:00+0000",
"id": "MYID"
}
...
The post in question displays on the Facebook page with a photo included, but there is not 'photo' object (or anything similar) returned in the API data. How do I access the picture URL for this post? Thanks in advance.
This request will fetch posts and the media information for the first image for each post.
/posts?fields=attachments{media}?access_token=YOUR_ACCESS_TOKEN
Sometimes posts contain multiple images. If you'd like to support that you need to fetch the subattachments also:
/posts?fields=attachments{subattachments{media}}?access_token=YOUR_ACCESS_TOKEN
Note that this method usually only provides image URLs that are up to 720px wide. If you want higher resolution imagery, you need to access data[0].attachments.data[0].subattachments.data[0].target.id to get the actual image ID which you can then use to perform an additional query /IMAGE_ID_HERE?fields=images to obtain the higher resolution image. Increment the numbers to get additional posts and images inside each post.

facebook v2.2 current_location is missing (no fql)

Before version 2.1 i was using fql to get user public information using the following code.
"https://graph.facebook.com/fql?q=select uid,name,current_location from user where uid = xxx"
Then i would parse the country, state and city from the response.
without fql we are using location field which leads to a page and the page gives longitude and latitude.
How do i get the country in v2.2 (The name or country code)
Thanks
You can easily get the location with Graph API using /user
refer to below link.
https://developers.facebook.com/docs/graph-api/reference/v2.2/user
https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=me%3Ffields%3Dlocation&version=v2.2&

API for Get venues for nearrby Location in foursquare

1)I want to fetch the venues for the nearby location by passing the latitude and longitude of to the API in foursquare.
I got this url:-thisand i got peroper response.
But for this latitude and longitude:- 32.3456,141.4346
(url)
I did not get any data.
Same for Facebook.I use this :- facebook API
But i want the list of generalized category listing from this API.And this API only gives me data of hotels only.Because i pass q=hotel.
2)How to get oauth_token for foursquare?
Please help me.
The reason you did not get any data for that location is because there are no venues in that area. If you follow this link you will see that location is in a remote area of Australia.
For help with connecting users to Foursquare, you can use these instructions

Facebook API: how to post status update with location (latitude + longitude)?

Need to post status update and attach user location by passing latitude and longitude. In FB docs they say, we need to pass "place" FB entity that is:
"an object containing id and name of Page associated with this location, and a location field containing geographic information such as latitude, longitude, country, and other fields (fields will vary based on geography and availability of information)"
How to create/get such place name from latitude and longitude? I'v read related post1 and post2 but was not able to find a working solution.
How to create/get such place name from latitude and longitude?
There is currently no API available for developers to create Facebook pages or places. However, you can get place name by doing a FQL query like this...
'SELECT page_id,name,latitude,longitude FROM place WHERE distance(latitude, longitude, "LAT_HERE", "LON_HERE") < 250`
250 refers to the radius(m) that it will search within, it can go up to 50000.
Doing this FQL query will return you the Facebook Place Page's id, place name, latitude and longitude.
(Actually there is no need to get the place name as the page_id is what you really need. With page_id, you will be able to get all the information of that Facebook Place Page.)
Need to post status update and attach user location by passing
latitude and longitude.
Assuming you are actually trying to publish a checkin, you can refer to the references below to proceed further with the data you have obtained from the FQL query...
A normal status update(feed dialog) is different from a status update with location tagged to it(checkins), they are using different APIs.
References:
How to get place_id before checkin?
Facebook - Publish Checkins using PHP SDK/JavaScript SDK
Facebook Documentations
Page FQL - http://developers.facebook.com/docs/reference/fql/page/
Checkins API - http://developers.facebook.com/docs/reference/api/user/#checkins
If you have the lat/long data, you can search for the place and get the place-id which can be included in the POST message.
Please check these related posts -
https://developers.facebook.com/docs/opengraph/actions/#taggingplaces
https://developers.facebook.com/blog/post/2012/03/07/building-better-stories-with-location-and-friends/

Facebook graph API: ID of user profile picture

Is there a way to get the ID of the picture that is the current profile picture for a user?
Edit: OK, seems there is no trivial way to get the ID!
However, it appears from random testing that every user has a single album with attribute type="profile", and the first image in this album is always the profile picture, so it is possible to get the ID of the profile picture that way. Can some more experienced with Facebook confirm that this is indeed always the case?
You can get the users public profile photo from the following url:
https://graph.facebook.com/[id]/picture
Reference:
http://developers.facebook.com/docs/reference/api/
The answer seems to be yes
e.g., the photos in an album have an ID (the profile photo is a different object though, which a different FB ID). An ID for every object is a core concept of FB's new graph API: Every object in the social graph has a unique ID.
Indeed, data request i have ever made through the FB Graph API returns (when successful) a response in the form of a JSON array, comprised of nested ID-Value pairs, e.g. the education field from a User object:
"education": [
{
"school": {
"id": "126533127390327",
"name": "Massachusetts Institute of Technology"
},
"year": {
"id": "140829239279495",
"name": "1992"
},
"concentration": [
{
"id": "192578844099494",
"name": "Computer Science"
}
],
"type": "College"
}
The profile photo is a connection of the User object (i.e., every FB object has Fields and Connections).
According to the table in the relevant FB Developer Page, a call to the Graph API requesting picture (user's profile photo(s)) returns a string which is the URL for the user's profile picture.
But why doesn't this same call return the user's profile photo ID?
The reason i suppose is that the URL returns:
Graph API : User Properties
The user's profile photo is not there, but in an adjacent node:
Graph API : User : Connections : picture
(See FB Documentation for Graph API structure here).
When you make that API call, examine the Request Headers, and in particular, the Request URL; when you do, you'll see something like this:
http://profile.ak.fbcdn.net/hprofile-ak-snc4/32093_100005743929541_5467982_q.jpg
The string between the underscores (100005743929541) is the user ID. this is easy to verify by making another call to the Graph API. From your browser location bar (assuming you are logged into Facebook) just enter:
https://graph.facebook.com/me
So again, the first item in that JSON string is the user's FB ID. Given that, it seems to me that if user profile ID does indeed have its own ID, then that string (user's FB ID) plus the two smaller adjacent strings of integers on either end of the ID, should be it--in other words, 32093_100005743929541_5467982 in the Request URL above.
Finally, perhaps the best way to answer this is by using the new Graph API Explorer. (I just tried to verify this, but my requests are hanging.)
There is one more simple way to accomplish this task.
Fetch all facebook albums by https://graph.facebook.com/me/albums?access_token=.
Loop into the albums and check if object type == 'profile'.
Get the value of object cover_photo where type == 'profile'.
This value of cover_photo is the id of profile pic of the user.
You can check it by https://graph.facebook.com/<cover_photo value>?access_tokne=
I don't know if you still need this but this is the way I did it in PHP:
$albumsfb = $facebook->api('/me/albums/?fields=type');
$albumsfb = $albumsfb['data'];
foreach ($albumsfb as $albumfb) {
if ($albumfb['type']=='profile'){
$albumprofile = $albumfb['id'];
break;
};
}
$photoprofilefb = $facebook->api('/'.$albumprofile.'/?fields=cover_photo');
$photoprofilefb = $photoprofilefb['cover_photo'];
$photoprofilefb = $facebook->api('/'.$photoprofilefb);
$fotoperfilfburl = $photoprofilefb['source'];
Instead of "me", put the user id that you want?
http://graph.facebook.com/<SOCIAL-ID>/picture?type=<small|normal|album|large|square>
SOCIAL-ID = Facebook returned social id.
small|normal|album|large|square = size of image.
I recently tried to like one of my friend's profile pictures from the Graph API explorer
Here's how I got the id of his current profile pic:
fields=friends..fields(albums.fields(photos.fields(id,name,link),name))
If you have used the Graph API explorer, you might be aware of the above line of code that's generated in the textEntry when you tick the checkboxes. The limit size is up to you, I just kept it 1 to receive the JSON object quickly (without the limit, it took me 5 minutes to get the JSON object containing a lot of information).
So here are the things you need to check in the Graph API (maintain the order):
Friends
Within Friends Albums
Within Albums Name and Photos (Within Photos the id and name of the photo)
I made a PHP script to like all the profile pictures of my friends :)