2017-10-16 42 views
1

好吧,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一直試圖在過去的日子,沒有運氣做到這一點...完成一個很多研究。如果網上有資源解釋如何處理這個問題,請點擊下面的鏈接。任何幫助是極大的讚賞。謝謝:)

回答

0

找到了解決方案!會後爲別人誰可能需要幫助,今後類似的問題的答案..

在我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 %> 
相關問題