我在auth变量中保存我的omniauth,如下所示
auth = request.env["omniauth.auth"]
当我按如下方式检查时
puts auth.inspect
它给了我
#<OmniAuth::AuthHash credentials=#<OmniAuth::AuthHash secret="ouAWj4Hvb9qwKiDDd66ewI8Hq8pDHj8dtfgdlmvdeJDSxY8" token="136631281-Ruduz2BesDwNwcBlwCaV90H358LCA0rCfLonMCE9"> extra=#<OmniAuth::AuthHash access_token=#<OAuth::AccessToken:0x00000003f77968 @token="136631281-Ruduz2BesDwNwcBlwChghaV90H358LCA0rCfLonMCE9", @secret="ouAWj4Hvb9qwKiDDd66ewgdrfgI8Hq8pDHj8lmvdeJDSxY8", @consumer=#<OAuth::Consumer:0x00000003fdf0cb18 @key="UN8w8rgfdDodjpLVgbWFvzCw", @secret="P2MbbeW4LiIyuuSc5gcQ26hcKzQJEyfBgfdyY5g39p2bo0", @options={:signature_method=>"HMAC-SHA1", :request_token_path=>"/oauth/request_token", :authorize_path=>"/oauth/authenticate", :access_token_path=>"/oauth/access_token", :proxy=>nil, :scheme=>:header, :http_method=>:post, :oauth_version=>"1.0", :site=>"https://api.twitter.com"}, @http=#<Net::HTTP api.twitter.com:443 open=false>, @http_method=:post, @uri=#<URI::HTTPS:0x00000003f76cc0 URL:https://api.twitter.com>>, @params={:oauth_token=>"136631281-Ruduz2BesDwNwcgrBlwCaV90H358LCA0rCfLonMCE9", "oauth_token"=>"136631281-Ruduz2BesDwNwcBlgrfwCaV90H358LCA0rCfLonMCE9", :oauth_token_secret=>"ouAWj4Hvb9qwKiDDd66ewI8grHq8pDHj8lmvdeJDSxY8", "oauth_token_secret"=>"ouAWj4Hvb9qwKiDDd66ewI8Hq8pDHj8lmvdeJDSxY8", :user_id=>"136631281", "user_id"=>"136631281", :screen_name=>"sanyagrfks", "screen_name"=>"sangryamrocks"}, @response=#<Net::HTTPClientError 429 Too Many Requests readbody=true>> raw_info=#<OmniAuth::AuthHash errors=[#<OmniAuth::AuthHash code=88 message="Rate limit exceeded">]>> info=#<OmniAuth::AuthHash::InfoHash description=nil image=nil location=nil name=nil nickname=nil urls=#<OmniAuth::AuthHash Twitter="https://twitter.com/" Website=nil>> provider="twitter" uid="136631281">
知道我正在使用auth['provider']
来访问提供商值
我想在auth中读取@params中的值,并想要访问值:oauth_token
,我怎样才能得到它
帮帮我
提前谢谢
答案 0 :(得分:0)
您可以从凭证哈希中获取令牌和密码。只需按照此代码获取令牌和秘密
@token = auth [“credentials”] [“token”]
@secret = auth [“credentials”] [“secret”]
答案 1 :(得分:0)
即使我遇到了这个问题,如果你想访问密钥,那么你可以像
那样访问它env["omniauth.auth"]["extra"]["access_token"].consumer.key
or
env["omniauth.auth"]["extra"]["access_token"].secret
访问@secret