Determining if users are facebook friends (Parsing) -
i'd find out if current user friends root node user, using koala, , if so, print statement saying: friends. problem parsing of data returned facebook.
user.rb
def facebook @facebook ||= koala::facebook::api.new(oauth_token) block_given? ? yield(@facebook) : @facebook rescue koala::facebook::apierror => e logger.info e.to_s nil # or consider custom null object end def facebook_friend facebook.get_connection("me", "friends/#user.user_id") end
profile.html.erb
<% if current_user.facebook_friend.include?(@user.uid)? %> <p> friends</p> <% else %> <p> not friends</p> <% end %>
output:
<%= current_user.facebook_friend %>
will return: [{"name"=>"elizabeth", "id"=>"100008217009369"}]
<%= @user.uid %>
will return: 100008217009369
thanks!!!
it easier thought: in user model simple used koala method:
def facebook_friend(user) facebook.get_connection("me", "friends/#{user.uid}") end def my_friends_list facebook.get_connection("me", "friends") end
then in profile view, adding current_user , @user arguments:
<% if @user.uid.present? %> <% if signed_in? && current_user == @user %> <p><%= current_user.my_friends_list.count %> friends</p> <% elsif current_user.facebook_friend(@user).empty? %> <p><%= current_user.mutual_friends.count %> friends in common</p> <% else %> <p>you facebook friends</p> <% end %> <% else %> <p>not connected</p> <% end %>
Comments
Post a Comment