【问题标题】:RUBY: Get the Steam Username from OmniAuthRUBY:从 OmniAuth 获取 Steam 用户名
【发布时间】:2015-08-12 07:59:33
【问题描述】:

我一直在使用 Omniauth 检索包含 Steam 用户名的环境。

输出如下:

<OmniAuth::AuthHash::InfoHash image="https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/d4/d45a66fee7932d270ec32d4457d865b485245cf1_medium.jpg" location="YT, CA" name="Daiki" nickname="Corybantic Walrus" urls=#<OmniAuth::AuthHash FriendList=#<URI::HTTP:0x0000000614f590 URL:http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=4A8837BF7A6C439681B57F4962D8B011&steamid=76561198128055024&relationship=friend> Profile="http://steamcommunity.com/id/hatterkiller/">> provider="steam" uid="76561198128055024">

我真的不知道如何在 Stack Overflow 中格式化它,所以这里有一个更清洁的 Pastebin

我需要的信息在代码的&lt;Omniauth::AuthHash::Infohash 里面。有没有办法使用 Ruby 检索用户名(昵称)并将其放入数组中?

有点像这样,但这仅适用于以前的输出格式:

    auth = request.env['omniauth.auth']

 session[:current_user] = { :nickname => auth.info['nickname'],
                                      :image => auth.info['image'],
                                      :uid => auth.uid }

【问题讨论】:

    标签: ruby-on-rails ruby steam-web-api


    【解决方案1】:

    类似这样的:

    session[:current_user] = {
      nickname: auth[:info][:nickname],
      image:    auth[:info][:image],
      uid:      auth[:uid]
    }
    

    【讨论】:

    • 哪里来的authvariable,来自request.env["omniauth.auth"]
    • 对不起! auth = request.env['omniauth.auth']
    • 这很简单,在分配session[:current_user] 之前尝试做logger.info auth.inspect 以确保有值。
    • 好的。所以他们确实有价值观。我设法将它们“放置”到我的输出 index.erb 页面上,并使用以下 {"nickname"=&gt;"Corybantic Walrus", "image"=&gt;"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/d4/d45a66fee7932d270ec32d4457d865b485245cf1_medium.jpg", "uid"=&gt;"76561198128055024"} 作为输出。我当前在索引 erb 中的 &lt;p&gt;&lt;%= session[:current_user][:nickname] %&gt;&lt;/p&gt; 不起作用。还有其他方法吗?
    • 试试session[:current_user] = { nickname: request.env["omniauth.auth"][:info][:nickname], image: request.env["omniauth.auth"][:info][:image], uid: request.env["omniauth.auth"][:uid] }
    猜你喜欢
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    • 2015-09-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-11
    相关资源
    最近更新 更多