2015-01-10 51 views
0

我一直在收到︰未定義的方法`趨勢'的Twitter :: REST ::趨勢:模塊當我執行Twitter的寶石。使用Twitter的熱門話題寶石

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。任何想法可能是什麼?謝謝大家的時間。

回答

0

有相同的問題,並找到您的文章。這是爲我工作的。

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在您的應用程序。我認爲它以字符串形式返回,所以我將它轉換爲散列以便訪問它。