【问题标题】:Trending Topics Using Twitter Gem使用 Twitter Gem 的热门话题
【发布时间】:2015-03-08 10:35:50
【问题描述】:

当我实现 twitter gem 时,我不断得到:Twitter::REST::Trends:Module 的未定义方法“趋势”

require "twitter"
class StaticPagesController < ApplicationController
    def home
        client = Twitter::REST::Trends
        @trends =client.trends(id=1, options={})
    end
end

我对 Rails 很陌生,所以我可能缺少一些愚蠢的东西,但我似乎无法在网上的任何地方找到正确的解决方案。根据我的理解 client.trends(id=1, options={}) 应该是文档 http://www.rubydoc.info/gems/twitter/Twitter/REST/Trends 中的 Enumerable 。知道它可能是什么吗?感谢大家的时间。

【问题讨论】:

    标签: ruby-on-rails rest twitter


    【解决方案1】:

    有同样的问题并找到了您的帖子。这对我有用。

    class TwitterApi
    
    def self.trending_tweets
    client.trends(id=1, options = {})
    end
    
    def self.client
    @client ||= Twitter::REST::Client.new do |config|
    config.consumer_key        = ""
    config.consumer_secret     = ""
    end
    end
    end
    

    用你的替换密钥和秘密,然后在你的应用程序中调用 TwitterApi.trending_tweets.to_h。我认为它以字符串形式返回,因此我将其转换为哈希以便访问它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-10
      • 2017-10-07
      • 2013-05-24
      • 2010-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多