2011-05-18 67 views
2

在我User模型中,我有以下代碼:只得到響應代碼,而不是實際的響應,從OAuth的::的accessToken

def twitter_client 
    OAuth::AccessToken.new(twitter_oauth, self.access_token_key, self.access_token_secret) 
end 

def twitter_oauth 
    OAuth::Consumer.new(Twitter::Login.consumer_key, Twitter::Login.secret, :site => Twitter::Login.site) 
end 

這樣我可以調用用戶#twitter_client像這樣:

current_user.twitter_client.post('/statuses/update.xml', {'status' => 'foooo', 'Accept' => 'application/xml'}) 

這種運作良好,而實際上並更新狀態,並返回如下:

#<Net::HTTPOK 200 OK readbody=true> 

這對於更新狀態確實不是問題。然而,當我想獲得最新的鳴叫,我得到的是一個響應代碼的對象,而不會從響應的實際內容:

current_user.twitter_client.get('/statuses/user_timeline.xml', {'Accept' => 'application/xml'}) 
=> #<Net::HTTPOK 200 OK readbody=true> 

這返回的對象僅僅是Net::HTTPOK一個實例,並且不包含鳴叫的數據。

如何獲取推文數據?

回答

7

怎麼樣...?

res = current_user.twitter_client.get('/statuses/user_timeline.xml', {'Accept' => 'application/xml'}) 

puts res.body 
+0

謝謝。對不起,答案是如此明顯! – user94154 2011-05-27 21:37:35

+1

明顯比晦澀難懂! (至少你有機會:) – iain 2011-05-28 07:40:34

相關問題