How do I know if a Facebook Status/Photo/Link is Private? - facebook

When I'm getting a status/link/photo from facebook API, how do I know if it has been shared with the public or if it's a private post?
Also - is there a way to query only public posts?
I'm currently using the /<username>/status /<username>/links /<username>/photos endpoints.

With the graph api
From the 3 endpoints you are using, only one gives you access to the privacy settings the /<username>/links. It returns a privacy object, something like this:
{
"id": "USER_FB_ID",
"links": {
"data": [
{
"id": "ID_OF_THE_POST",
"from": {
"name": "Fábio Antunes",
"id": "USER_FB_ID"
},
"message": "Check this awesome link",
"privacy": {
"description": "Friends; Except: Restricted",
"value": "ALL_FRIENDS",
"allow": "",
"deny": "",
"networks": "",
"friends": ""
},
(etc....)
With FQL
To solve your problem you could use FQL this way you can get the 3 endpoints that have public access.
For the links you can use this query:
Select link_id,owner_comment, title, url, privacy FROM link WHERE owner = me() AND privacy.value='EVERYONE'
note: check the link table to see if there are any fields that you may want to add to this query
Since the links table from the 3 endpoints is the only with privacy settings structure to get the user photos and statuses that are public you will have to use the privacy table.
To get all the users public photos I made 2 joins, first I'm getting the user photos, then I want the privacy settings of the photos that are available to everyone and then I select the photos that have the privacy settings public:
SELECT caption,src_big FROM photo WHERE object_id IN (SELECT id FROM privacy WHERE value='EVERYONE' AND object_id IN (SELECT object_id FROM photo WHERE owner=me()))
note: check the photo table to see if there are any fields that you may want to add to this query
To get the public statuses it's the same process for the photos, two joins:
SELECT status_id , message, place_id FROM status WHERE status_id IN (SELECT id FROM privacy WHERE value='EVERYONE' AND object_id IN (SELECT status_id FROM status WHERE uid=me()))
note: check the status table to see if there are any fields that you may want to add to this query

Related

Get user id and name from comment on Fan Page Wall

Since Facebook API update to v2.11, I cannot get User Id and Name from comments on FanPage Wall Post. Anyone can help/explain?
Usually I used this :
https://graph.facebook.com/[POST_ID_PAGE]/comments?order=reverse_chronological&access_token=[YOUR_ACCESS_TOKEN]
And the result just like :
{
"data": [
{
"created_time": values_date_TMZ,
"from": {
"name": USER_NAME,
"id": USER_ID
},
"message": THE_COMMENT,
"id": THE_COMMENT_ID
}
}
You need a Page Token now, to get user names - check out the changelog:
https://developers.facebook.com/docs/graph-api/changelog/version2.11#gapi
I assume you are using an App Token at the moment.
Edit: Of course it has to be a Page Token of the Page with the comment. And of course you need to manage the Page - else you would not even get a Page Token.

How to get FB group by alias (FQL)

Does there exist any way to get group by it's alias (username)?
SELECT id, name, pic_big, type, url, username FROM profile WHERE username='somealias'
works for pages, but doesn't works for groups! For groups it returns
(#803) Some of the aliases you requested do not exist: somealias
profile table is like a parent class for user, group, page, event, or application tables. (see https://developers.facebook.com/docs/reference/fql/profile/)
It has field username but values in this field are filled from related tables, and table group has no field username (see https://developers.facebook.com/docs/reference/fql/group). So when we query profile using where id = someid we get such results:
SELECT id, name, pic_big, type, url, username FROM profile WHERE id= '195466193802264'
{
"data": [
{
"id": 195466193802264,
"name": "Facebook Developers",
"pic_big": "https://www.facebook.com/images/litestand/bookmarks/sidebar/icons/groups/icon-default.png",
"type": "group",
"url": "https://www.facebook.com/groups/195466193802264/",
"username": ""
}
]
}
As you can see, username is empty for group.
update
After some investigation I found that groups CAN have usernames. Oficially they can't, but group's email part before # symbol is it's username.
When you query the profile if you only specify its username you receive nothing. But if you'll add its name your group will appear.
Example:
SELECT id, name, pic_big, type, url, username FROM profile
WHERE username = 'rock.mfc' and type = 'group'
will result
{
"data": [
]
}
But the query
SELECT id, name, pic_big, type, url, username FROM profile
WHERE name = 'ROCK MUSIC FANS CLUB' and username = 'rock.mfc' and type = 'group'
will give the required result:
{
"data": [
{
"id": 268045023346892,
"name": "ROCK MUSIC FANS CLUB",
"pic_big": "https://www.facebook.com/images/litestand/bookmarks/sidebar/icons/groups/icon-guitar.png",
"type": "group",
"url": "https://www.facebook.com/groups/rock.mfc/",
"username": "rock.mfc"
}
]
}
Hope it'll help you.

Get List of Members of a public group from Facebook

I want to get list of ALL members of a public group using Facebook API ( preferably via FQL ). I checked https://developers.facebook.com/docs/reference/fql/ .. The table group_member does not provide such API !
Any inputs ? As this is a public group ; do we need to send any auth_access tokens ! Something like https://graph.facebook.com/fql?q=SELECT%20url,normalized_url,share_count,like_count,comment_count,total_count,commentsbox_count,comments_fbid,click_count%20FROM%20link_stat%20WHERE%20url='google.com'
works fine without any tokens..
No permissions are needed.
To read the group_member table you need:
any valid access_token if the group is public (i.e. the group's
privacy setting is OPEN)
Source: https://developers.facebook.com/docs/reference/fql/group_member/
Using Graph API
GROUP_ID/?fields=members
{
"id": "GROUP_ID",
"members": {
"data": [
{
"name": "User's name",
"administrator": false,
"id": "User's ID"
},
...
Using FQL
SELECT uid FROM group_member WHERE gid = GROUP_ID
{
"data": [
{
"uid": "100004123456789"
},
...
just follow this link https://www.facebook.com/groups/{your group id}/apps/store and add your facebook app

FaceBook API for friends count

There is the question about fetching count of user friends via FaceBook API.
I want to get the number of friends only have USER_ID of the any facebook user. As I know I can get it using FQL like:
SELECT friend_count FROM user WHERE uid = X
But for some users this value is null or there is no value. Please advice is there another way to get this value?
That user might be keeping that information private. In that case, you cannot fetch that information.
You just check the following link. You need to generate token (by clicking on Get Token you will get it) with data you want from facebook API, need to select friends option to get the friend count.
https://developers.facebook.com/tools/explorer/?method=GET&path=me%3Ffields%3Did%2Cname%2Cfriends&version=v2.8
FB.api(
'/me',
'GET',
{"fields":"id,name,friends,link,email,gender,picture,first_name,last_name,cover"},
function(response) {
// Insert your code here
}
);
after executing this you will get this in response as
{
"id": "XXXXXXXXXX",
"name": "Test test",
"friends": {
"data": [
],
"summary": {
"total_count": 14
}
}
}
total_count will be your friend count

FQL query of photos for Facebook users with large numbers of photos

I need to get photos of an FB user sorted by likes.
I ran this FQL query via Facebook JavaScript SDK to get them:
SELECT object_id, src_big, src_big_width, src_big_height, link, like_info, caption, created
FROM photo
WHERE owner = MANY_PICS_USER_ID ORDER BY like_info DESC LIMIT 10
The query fails for users with more than 3000 photos. Turns out there are a lot of those users. Related Facebook bug is here http://developers.facebook.com/bugs/438568326189781
As a note: removing "ORDER BY like_info" makes query work, but there is no easy way for me to get those pictures, sorted by likes
To reproduce:
Pick a FB friend with at least 3000 photos, get their user Id, and run the above query (replacing MANY_PICS_USER_ID) in API GRAPH EXPLORER.
What is the best workaround? Or, can you suggest the easiest light-weight Open Graph solution?
To sort photos by likes you need the following:
Run the query which gives first 100 results (replace me with user id):
http://graph.facebook.com/me/photos?fields=id,source,likes&limit=100
Which return the following data structure:
"data": [
{
"id": "1234567890",
"source": "http://photo.url.in.facebook.cdn.com/",
"created_time": "2012-09-13T22:52:34+0000",
"likes": {
"data": [
{
"id": "1234567890",
"name": "Full Name"
},
.....
"paging": {
"next": "https://graph.facebook.com/1234567890/likes?limit=25&offset=25"
}
}
},
{
"id": "312323232323",
"source": "PICTURE_URL",
"created_time": "2012-09-12T20:54:27+0000",
"likes": {
"data": [..]
}
},
....
"paging": {
"previous": "http://PREVIOUS_URL?fields=id,source,name,height,width,link,likes&limit=100&since=123456",
"next": "http://NEXT_URL?fields=id,source,name,height,width,link,likes&limit=100&until=234567"
}
If total number of pictures is more than 100, run all next queries,
from the "next" link until the num of pics will be less then 100.
For every picture you need to count total number of likes. If the
number of likes is more than 25, run extra query from
likes.paging.next until number of likes will be < 25 and get the
total quantity.
Sort all those pics by number of likes.
So for the user with 3000 pics it will be in total 30 calls + extra calls for each picture with more than 25 likes.