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.
Related
This should be an easy one. All I want it the user's profile url.
I've tried the following FQL:
SELECT profile_url FROM standard_user_info WHERE uid = me()
but get the Request Failed error. I'm using the Graph API Explorer / FQL Query and have the latest Access Token.
Basically I'm looking for the FQL equivalent to this Graph API call:
https://graph.facebook.com/me?fields=link
Thanks for the help
If you read the documentation properly, you'll notice that-
standard_user_info requires the APP_ACCESS_TOKEN, instead of USER_ACCESS_TOKEN. You can get the App Access Token from the Access Token Tool, for the testing.
You can get the information about the authorized app users only.
So, you can test it like this-
SELECT profile_url FROM standard_user_info WHERE uid = USER_ID
Note: Don't use me() (since you are using the app access token now which didn't recognize me()), instead use you ID)
According to the FQL Stream documentation the following query is supposed to return impression counts when run by an authenticated page owner, yet it never does. We have the page owner authenticating directly in the graph api explorer with extended permissions (read_stream, read_insights), but the impression counts are always null.
Is anyone able to get this working?
SELECT post_id, actor_id, message, impressions FROM stream WHERE actor_id = {owned_page} and source_id = {owned_page}
I think its missing in the documentation, but you should make this call using the page access token instead of user access token to get it worked.
So here are the steps:
Get the following permissions from the user and get the user access_token:
manage_pages - to get the page access token
read_insights - to read the impressions (as mentioned in the doc)
read_stream - for all posts that the current session user is able to view
Using that token, get the page access_token with the call-
/{page-id}?fields=access_token
(optional) Check out my answer here to extend this page access token that will never expire. (Basically to avoid some steps)
Using the page access token, run your query-
SELECT post_id, actor_id, message, impressions FROM stream WHERE actor_id = {owned_page} and source_id = {owned_page}
This will fetch you the impressions(if any) in the result.
Hope that helps.!
Today I started get some strange FQL Error.
FQL query: *SELECT target_id FROM connection WHERE source_id = user_id1 AND target_id = user_id2*
*SELECT uid FROM user WHERE has_added_app=1 and uid IN (SELECT uid2 FROM friend WHERE uid1 = "user_id")*
FQL Response (Error): Error: Requires extended permission: read_stream
What is it???
Help.
According to their Change Log, on 2011-09-18, Facebook pushed this update:
FQL connection table now requires read_stream permission. (rE435878)
I had the same problem. I was only using the connection table to get a list of friends, so I was able to change to the friend table to pull the info I needed.
Stuff like this is what makes Facebook Platform a hostile development environment.
Looks like facebook has changed some of the required permissions for some actions this night. The same happened to me. You need to ask for read_stream permissions. For more information refer here
P.S: You might need to remove the application from your profile and add it again with the new permissions
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
Using Facebook's Graph API, given a username xyz (assuming they've authenticated my site), how do I get a list of all of the facebook pages that the user administers?
The accounts property on the user object says:
The Facebook pages owned by the current user. If the manage_pages permission has been granted, this connection also yields access_tokens that can be used to query the Graph API on behalf of the page.
http://developers.facebook.com/docs/reference/api/user
After getting access token you can get all details of list of all of the facebook pages that the user administers.
https://graph.facebook.com/[FACEBOOKUSERID]?metadata=1&access_token=
The output will look like
{
"name": "Facebook Developer Garage Austin - SXSW Edition",
"metadata": {
"connections": {
"feed": "http://graph.facebook.com/331218348435/feed",
"picture": "https://graph.facebook.com/331218348435/picture",
"invited": "https://graph.facebook.com/331218348435/invited",
"attending": "https://graph.facebook.com/331218348435/attending",
"maybe": "https://graph.facebook.com/331218348435/maybe",
"noreply": "https://graph.facebook.com/331218348435/noreply",
"declined": "https://graph.facebook.com/331218348435/declined"
}
}
}
Use an fql query! That is the best way to get the pages for which the user is admin. You will also be able to restrict the names also. i.e pages with empty names A sample fql query which gives you the page details as well.
SELECT page_id,page_url,name,pic_square FROM page WHERE page_id IN (SELECT page_id FROM page_admin WHERE uid = " + **UserId** + ") and name!=''
UserId -- Id of the admin
NOTE
This method will not work from version 2.1 of graph api as fql was deprecated from that version onwards
I found the answer, you need to use FQL, passing in the appropriate access_token:
https://api.facebook.com/method/fql.query?query=SELECT%20page_id%20FROM%20page_admin%20WHERE%20uid=XXXX&access_token=YYYY
Here's what I use. It works perfect
$pages = $facebook->api(array('method' => 'fql.query','query' => 'SELECT page_id FROM page_admin WHERE uid = '.$uid.''));
foreach($pages as $k=>$v) {
echo 'page id#:'.$v['page_id'].'<br/>';
}
This is of course after you have the session created for the fb user! The $uid would be the profile id# of the specific facebook user your returning of a list of managed pages for.
#rmorrison - This is not graph API though. With the new "like" addition, you can use this URL: h ttps://graph.facebook.com/me/likes?access_token=blah! or h ttps://graph.facebook.com/USER_ID/likes?access_token=blah!
Fql is the best way to get the pages of the user for which he is the admin. As the others like likes of user will give all the pages that the user like.
You can get list of pages from a simple Facebook Graph API Hit.
https://graph.facebook.com/{user-id}/accounts?access_token={access-token}
It will give a list of pages for user which he/she has created.
access_token is valid for an hour or less. What should someone do in order to get the details even after. I was trying to result get the result from
https://graph.facebook.com/v2.3/search?q=coffee&type=place¢er=37.76,-122.427&distance=1000&access_token=xyz
This worked for an hour or so but how do i get the result after an hour...without going for a login.