I'm fetching my friends using the Koala gem for Rails framework like that:
#friends = current_user.facebook.get_connections("me", "friends?fields=id,name,picture.type(small)")
The question is: how do I fetch my friends ordered by name, for example ?
Use FQL or post process it in Ruby.
So for FQL in Koala, something like
current_user.facebook.fql_query(my_fql_query)
Where my_fql_query is
SELECT uid, name, pic_small FROM user WHERE uid in (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY name
Related
I am implementing search functionality in rails. When i search for users, the logged in user who is searching also comes in search. I want to avoid it.
This is in my search_method in controller
#matchedUsers = InUser.where("first_name like ?", "%#{params[:searchfnameInput]}%")
And i have user id in session[:user_id]. I want to exclude the record having id==session[:user_id] from #matchedUsers?
Thanks and Regards
Add another where clause to your query:
#matchedUsers = InUser.where("id<>?", current_user.id).where("first_name like ?", "%#{params[:searchfnameInput]}%")
The "id<>?" says "exclude the user with this ID".
I am building a rails app where there is an image gallery and users will be able to hit the facebook like button for each image they open. Each image can have its seperate page URL. I plan to use the facebook like plugin so that users can like the photos as web-pages. So far I was able to find that if I do https://graph.facebook.com/?id=http://www.mysite.com/ImagePage i get:
{
"id": "http://www.mysite.com/ImagePage",
"shares": 30
}
This leaves me with 2 problems.
The shares property is not exactly the total count of likes, it is only the count of times the link made it to the user's facebook wall. How do I get the number of likes?
Is there an eventHandler or something I can use to know when a user clicks Like? so that I can store that information? I want to store the likes count at my end so that I can show the gallery in the order of descending number of total likes in each day.
I have come across the rails Koala gem but I am not sure if I need to use that for my application yet, as I do not have the need to log in users using facebook login/connect. Please advise if you think I need to do so to do what I mentioned above.
you have to use FQL.
see this example in php, im sure you know how to handle it in ruby:
$fql = 'SELECT url, share_count, like_count, comment_count, total_count
FROM link_stat WHERE url="http://stackoverflow.com"';
$json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
result looks like:
[
{
"url" : "http://stackoverflow.com",
"share_count" : 1353,
"like_count" : 332,
"comment_count" : 538,
"total_count" : 2223
}
]
For those who don't know how to modify the code seen in the previous answer by yourself, you mostly have two choices:
Use facebook gems available that support running FQL queries (for example: fb_graph)
Sample code:
require 'fb_graph'
array = FbGraph::Query.new(
'SELECT name FROM user WHERE uid = me()'
).fetch(ACCESS_TOKEN)
p array
Use a simple Ruby code that basically just does FQL queries, as seen on this accepted answer (Facebook FQL Query with Ruby)
I am having trouble finding a user's friends at a specific location using the current_location attribute. This is my query:
SELECT name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND
current_location = 103723936333579
This always returns empty even though I know that many of the user's friends are living at the location with id 103723936333579. I know that current_location is an array, but if I write:
SELECT name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND
current_location.id = 103723936333579
... to get the id of the array I get an error. The dot-notation doesn't seem to be working for me.
Thanks
Facebook FQL queries don't support querying by an array element like you are trying to do. The only way I can think of is to return all users and their current_location field and loop through every user and their current_location value.
You need to prompt the user for friends_checkins extended permission to make sure the current_location value is populated.
I want to get all the checkins a user is tagged in (note: I am not interested in his own checkins). I tried the following, which is a little illogical and of course does not work, but you'll get what I am trying to do:
SELECT message FROM checkin WHERE tagged_uids IN
(SELECT uid FROM user WHERE uid = me())
Any ideas?
You're thinking of IN backwards. The query you're looking for is:
SELECT message FROM checkin WHERE me() IN tagged_uids
However, tagged_uids is not indexable, so you'll need to know more information before you can run this query (like who is actually recording the checkin). One thing you could try is:
SELECT message FROM checkin
WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
AND me() IN tagged_uids
This will find all checkins in which your user is tagged that are by friends of the user (probably the only people who can check in that user anyway).
How to programmatically find which of my friends are using my application using Mogli or Facebooker2.
If the only way is to use FQL can someone provide an example?
I think the code bellow is able to find the
select uid, name, is_app_user from user where uid in (select uid2 from friend where uid1=me()) and is_app_user=1
Just tested:
https://api.facebook.com/method/fql.query?query=select+uid%2C+name%2C+is_app_user+from+user+where+uid+in+%28select+uid2+from+friend+where+uid1%3Dme%28%29%29+and+is_app_user%3D1%0A
&access_token=YOUR_ACCESS_TOKEN
&format=json
And is returning the correct results so FQL is actually working!