简体   繁体   English

使用Omniauth-Facebook gem存储user_likes

[英]Storing user_likes with the Omniauth-Facebook gem

Does anyone know where in the Auth Hash the user_likes are stored? 有谁知道在Auth Hash中user_likes存储在哪里?

I've tried different combos: 我尝试过不同的组合:

auth.extra.raw_info.user_likes
auth.extra.raw_info.likes

I've got the permission, I just don't know how to get to the user_likes array. 我获得了许可,我只是不知道如何访问user_likes数组。

Omniauth-Facebook gem Omniauth-Facebook的宝石

After some time (edit) 过了一段时间(编辑)

Alternatively I could do something like this using the HTTParty gem: 或者我可以使用HTTParty gem做这样的事情:

  url = "https://graph.facebook.com/#{auth.uid}/likes&access_token=#{auth.credentials.token}"
  @likes = HTTParty.get(url)

But I really want to know if its possible through the omniauth authentication process... 但我真的想知道它是否可能通过omniauth身份验证过程...

The omniauth-facebook gem uses the /me call to fill the raw_info hash. omn​​iauth-facebook gem使用/ me调用来填充raw_info哈希。 Per the facebook docs http://developers.facebook.com/docs/reference/api/user/ , likes are not included in the user object but are a connection that can be accessed by calling https://graph.facebook.com/me/likes . 根据facebook文档http://developers.facebook.com/docs/reference/api/user/ ,喜欢不包含在用户对象中,但是可以通过调用https://graph.facebook.com来访问/我/喜欢

Hope this response though late, helps someone who is trying to figure out what is inside the different hashes part of auth hash object (schema reference: https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema ) 希望这个反应尽管很晚,帮助那些试图找出auth哈希对象的不同哈希内部的人(架构参考: https//github.com/intridea/omniauth/wiki/Auth-Hash-Schema

Instead of trying different combinations (as posted in the question), one could simply render the object as an yaml to browser. 可以简单地将对象渲染为浏览器的yaml,而不是尝试不同的组合(如问题中所述)。 Now page source of the browser output would give a clear picture of what is returned part of the auth object. 现在,浏览器输出的页面源将清楚地显示auth对象的返回部分。 Other option is to put a debug break and inspect the auth object in the callback controller (an ide would be very helpful in this case). 其他选项是调试中断并检查回调控制器中的auth对象(在这种情况下,ide会非常有用)。

routes.rb 的routes.rb

 ...
 match '/auth/facebook/callback' => 'authentications#create'
 ...

authentications_controller.rb (or your controller that receives the call back) authentications_controller.rb(或接收回调的控制器)

class AuthenticationsController < ApplicationController
    ...


    def create
        # a simple code to understand the content of the auth object
        render :text => request.env["omniauth.auth"].to_yaml
    end
 end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM