我想知道当前用户是否是root节点用户的朋友,使用考拉,如果是,打印一条语句说:你们是朋友。我的问题是解析从 facebook 返回的数据。
用户.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 a 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> you are friends</p>
<% else %>
<p> you are not friends</p>
<% end %>
输出:
<%= current_user.facebook_friend %>
将返回:[{"name"=>"Elizabeth", "id"=>"100008217009369"}]
<%= @user.uid %>
将返回:100008217009369
谢谢!!!