【问题标题】:Using user's token to make requests to Twitter API in Rails在 Rails 中使用用户令牌向 Twitter API 发出请求
【发布时间】:2012-02-15 04:00:35
【问题描述】:

我正在使用 Omniauth 从 Twitter 获取特定用户的凭据。我得到的 OmniAuth 对象的一部分是这样的:

credentials=#
<Hashie::Mash secret="XXXX" token="XXXX">
extra=#<Hashie::Mash access_token=#<OAuth::AccessToken:xxxx @token="xxxx", @secret="xxxxx", ..

现在我正在为该特定用户存储credentials[token]UID。在某些时候,我想使用该特定用户的身份验证来获取 Twitter API,以避免获得对特定 IP 的最大 150 个请求。现在我只是这样做:

twitter_user_name = Twitter.user(user_id).screen_name

那么,我该如何使用 Twitter gem 使用 OmniAuth 提供的身份验证来发出这些请求,而不是从我自己的 IP 发出请求(未经身份验证的调用,因此受到限制)

【问题讨论】:

    标签: ruby-on-rails twitter omniauth


    【解决方案1】:

    玩了 gem 之后,我想出了怎么做:

    您想为特定用户创建一个新的 API 对象,所以您想这样做:

    client = Twitter::Client.new(:oauth_token => 'XXXXX', :oauth_token_secret => 'XXXX')
    

    并使用此客户端执行请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-22
      • 1970-01-01
      • 2019-11-23
      • 2018-02-25
      • 1970-01-01
      • 2012-08-19
      • 2013-12-19
      • 2012-04-22
      相关资源
      最近更新 更多