如何将Facebook Graph API JSON数据转换为我的数据库中已存在的用户?
问题描述:
好吧,Iv'e做了一些研究,但仍然没有运气...如何将Facebook Graph API JSON数据转换为我的数据库中已存在的用户?
我将解释什么,我想首先要做到:
我有一个应用程序,它只是通过Facebook登录。我希望这些用户看到他们的朋友也在使用我的应用程序的列表。
我路由了返回当前在应用程序上的用户朋友列表。这显示在JSON Data
。该数据返回如下:"name"=>"Example Name", "id"=>"32938293828393"
。在我的数据库中,我存储所有用户Facebook uid's
。我现在希望能够通过匹配返回的JSON id
来找到用户,方法是将它与存储在数据库中的uid
进行匹配。
这是我目前users_controller.rb
:
def index
@users = current_user.facebook.get_connections("me", "friends")
@value = '{"id":"name"}'
json = JSON.parse(@value).with_indifferent_access
@users.find(params[json[:id] == :uid])
end
,这是我index.html.erb
:
<%= @users.each do |user| %>
<%= link_to user.first_name, user %>
<% end %>
Iv'e一直试图在过去的日子,没有运气做到这一点...完成一个很多研究。如果网上有资源解释如何处理这个问题,请点击下面的链接。任何帮助是极大的赞赏。谢谢:)
答
找到了解决方案!会后为别人谁可能需要帮助,今后类似的问题的答案..
在我users_controller.rb
我现在有
class UsersController < ApplicationController
def index
@friends = current_user.facebook.get_connections("me", "friends")
uids = @friends.collect { |f| f["id"] }
registered_friends = User.where('uid IN (?)', uids)
@pals = registered_friends
end
end
现在我Users/index.html.erb
我现在有
<% @pals.each do |pal| %>
<%= link_to pal.first_name, wall_path(pal.id) %>
<% end %>