get facebook photo like count,share count,comment count - facebook

I writting a service that collect this counter of facebook posts. Users enter posts link, and then i get from the link the postID, and by using this FQL:
"SELECT like_info.like_count, comment_info.comment_count, share_count FROM stream WHERE post_id='xxx_xxxx' AND created_time > 01/04/2014 AND created_time < 02/04/2014 limit 1000",
I get this counters.
The problem I have is when user enter a link to facebook photo (for example: http://www.facebook.com/photo.php?fbid=10152281007419070&set=a.39727214069.46046.633269069&type=1&stream_ref=10),
then how do I get the postID? I know that the useriD is the number after the second dot in the link, but how do i get the other number?
Thanks in advance.

The post id in the url you have mentioned is the 101522....... ie just after fbid=
So, you can parse the url string and fetch the photoid

Related

How to get "news main stream" from the main facebook site?

How to get the general information listed on the home page?
Facebook makes a request to
https://www.facebook.com/ajax/pagelet/generic.php/LitestandMoreStoriesPagelet?
with params:
ajaxpipe
ajaxpipe_token
no_script_path
data
__user
__a 1
__dyn
__req
__rev
__adt
And although it returns a json (inside a script with conditions...) is not a clean answer.
Is there another way to get that data? I do not want to use the sdk.
If you want the 'News feed', you'll want to use the /user/home/ API endpoint:
https://developers.facebook.com/docs/graph-api/reference/v2.1/user/home
e.g. https://graph.facebook.com/me/home?access_token=VALID_ACCESS_TOKEN will just grab your own News Feed.
You can also filter by any of the 'filter_key' values returned from the FQL query (use the Graph API Explorer and API version 2.0):
SELECT filter_key, name, type, value FROM stream_filter WHERE uid = me()
e.g. adding the query string filter=app_2305272732 will return a feed of things from the 'Photos' app (i.e. photos added to Facebook by your friends)

How to get username of an user with fql?

I want to get all users with their name and facebook username in a group. The following query should do it but it doesn't return usernames.
SELECT name, username from profile where id in (SELECT uid FROM group_member WHERE gid = 'GROUP_ID')
Even though almost all users have an username, username field is null for each user in the result.
I don't think Facebook hides this information because of privacy issues because I'm able to get username with graph api using http://graph.facebook.com/uid.
That will only work with Graph API v1.0, which will be deprecated on April 30th 2015. With v2.0, it is no longer possible to get the username field.
See https://developers.facebook.com/docs/apps/changelog#v2_0_graph_api
/me/username is no longer available.
Username and name still can retrieve by using fql. But I don't think that you can simply get the name from the group by using general query like 'uid from groupmember', this is because Facebook secure the name of Facebook user. But you can get their name/username if that Facebook user has commented on your post.
This is the fql query to get the name/username of facebook user:
{
comments = "SELECT actor_id, target_id FROM stream WHERE post_id=\"" + postid + "\"",
commenters = "SELECT username, name FROM profile WHERE id IN (SELECT actor_id, target_id FROM #comments)",
}
If you the administrator of the group, of course you can simply get the post_id by using fql then use the post id to get the name/username.
Hope this can help to solve your problem.

How can I get all my posts to other people, not to my timeline?

How can i get, using Facebook Graph Api, all my posts to other people, not to my timeline?
I'm trying to use me/posts , but i get all my posts including to my timeline, and i couldn't separate it
Using Facebook FQL API:
SELECT post_id, created_time, description, description_tags, app_id,
message, type, created_time FROM stream WHERE source_id=me() AND
comment_info.can_comment!='' AND actor_id=me() AND permalink="" AND
created_time<=now() LIMIT 150
The only problem is this query doesn't return "Upload photo on friends wall"'s post, because of this unresolved bug at https://developers.facebook.com/bugs/148353975327544. However, this FQL query should works perfectly. Kindly let me know if you're figure out something wrong with this query.
Also, please make sure your user access token have granted "read_stream" permission.
comment_info.can_comment!='' used to exclude "Comment on friend's Status" story feed.
permalink="" used to exclude "Lim and 林果皞 are now friends." or "People changed his profile picture.", "林果皞 created an event."...etc. You can test what would happen if remove this.
Update for comment below:
I think what you can do is extract the id from description_tags which was no start with "0", for example my screenshot, id "100003013144869":
Also, extract the created_time, for example "1368624514"
Then, do a query with:
SELECT post_id FROM stream WHERE source_id='100003013144869' AND
actor_id=me() AND created_time=1368624514
I'm know it's not absolutely accurate(If 2 feed have the same created_time on seconds), however most likely you can make your job done.

realtime api feed - how to get new comments?

I made it to subscribe to the realtime api and retrieve update messages telling me the uid and time when the item changed. But how do I get the corresponding post/comment. I tried to use the fql but unfortunately there seems to be a bug in the fql when using updated_time.
This is my query:
SELECT post_id, actor_id, target_id, updated_time, message FROM stream WHERE source_id = me() AND updated_time >= "pushTime"
where pushtime is the time I got from the realtime notification.
It works for getting a standalone(no comments) post but as soon as there are comments it does not work. When I go through all posts and check the updated_time I can find the correct post.
My only solution for the time being is to iterate over all posts until i find the post where updated_time == "pushTime".
Anyone another solution?
If you have stored previous comments then retrieve the last comment ID you have stored and use that to query facebook for comments with an ID higher than that.

How can I count the total friends of a Facebook user by uid?

How can I count the total friends of a Facebook user by uid?
There is a friend_count field against the user table that you can query.
SELECT friend_count FROM user WHERE uid = me()
Just replace me() with the UID of the user that you want to query.
#Scott
This very much works, I didn't expect it to :)
https://graph.facebook.com/fql?q=SELECT friend_count FROM user WHERE uid = 273103345
I tried with a random user id who is not a friend in Graph API. However for few random uids it returned null, I am guessing they were pages.
FQL is now deprecated as of October 2014. Quoting Facebook's FAQ :
As of Tuesday 22nd July 2014, we now return a total_count field within
a summary property in the response to /v2.2/me/friends.
The user/friends endpoint does require the user_friends permission to return an actual list of friends who use your app, however the friend count field will still be returned without this the user_friends permission granted. Sample response:
{
"data": [
],
"summary": {
"total_count": 811
}
}
Full FAQ: https://developers.facebook.com/docs/apps/faq#total_friend_count
COUNT is not supported by FQL:
SELECT uid2
FROM friend
WHERE uid1 = USERID
Since COUNT is not supported you need to get all of the records and then count them in whatever application that is making the SQL call.
If you want to get more information, like names, along with count you can use an inner select to get the friend's extended info:
SELECT name
FROM user
WHERE uid IN (SELECT uid2
FROM friend
WHERE uid1 = USERID)
Here is a related SO question:
FQL result count
References for Friend table:
Query this table to determine whether
two users are linked together as
friends.
Heres my solution... works great!
$myfriends = $facebook->api('/XXXXXXX152466/friends');
$friendcount = COUNT($myfriends['data']) + 1;
Replace XXXXXXX152466 with the facebook profile id#
Using Facebook PHP SDK along with Graph API!
Starting with Facebook API 2.0 you can't get the full list of Facebook friends, only a partial list of friends that also authorized your app.
You can still get the total number of friends though, the Graph API user/friends has a field summary containing the count as total_count
So you can get it using:
FB.api("/me/friends", function (response) {
if (response && !response.error) {
console.log(response.summary.total_count);
}
});
There are lot of way to count the no of friends using Facebook Graph API with Php SDK, out of one i am telling..
$fbuser=$fb->api('/me/friends');
$access_token = $fb->getAccessToken();
$friend_count=0;
foreach($fbuser['data'] as $friends)
{
$friends_count++;
}
For complete tutorial visit this article Getting FB Friends Count