【问题标题】:how to display twitter user feed in rails with twitter gem如何使用 twitter gem 在 rails 中显示 twitter 用户提要
【发布时间】:2014-07-05 07:02:11
【问题描述】:

我正在使用 twitter gem for rails 来尝试显示我的 twitter 提要中的 3 个状态。我正在按照文档做所有事情,但它没有在我的视图中显示任何内容。

在我的应用程序控制器中,我把它记下来了:

client = Twitter::REST::Client.new do |config|
 config.consumer_key        = "***********"
  config.consumer_secret     = "***********"
  config.access_token        = "***********"
  config.access_token_secret = "***********" 

 end



def client.get_all_tweets(user)
    options = {:count => 3, :include_rts => true}
      user_timeline(user, options)
  end


  @tweet_news = client.get_all_tweets("tezzataz")

那么在我看来,我只是简单地说:

<% @tweet_news %>

我没有收到任何错误,但我的视图中没有任何显示。任何帮助将不胜感激!

【问题讨论】:

标签: ruby-on-rails ruby twitter twitter-oauth twitter-gem


【解决方案1】:

将其用于相同目的。

<ul>
  <% @tweet_news.each do |f| %>
    <li>
      <%= f.text%>
      <span><%= time_ago_in_words(f.created_at) %> ago</span>
    </li>
  <% end %>
</ul>

【讨论】:

    【解决方案2】:

    控制器

    require 'twitter'
    
    class TweetController < ApplicationController
      def index
        client = TweetController.create_client
        begin
          @tweets = get_tweets(client)
        rescue => e
          #TODO: render 404 with the error
           puts "Error : #{e.to_s}"
        end
      end
    
      private
      def get_tweets(client, userName)
        client.user_timeline(userName, :count => 200)
      end
    end
    

    查看

    <div class="row">
        <div class="col-lg-12">
            <ul class="timeline">
                <% @tweets.each do |tweet| %>
                        <div class="timeline-image">
                            <!-- Show user avatar (profile pic)-->
                            <img class="img-circle" src= '<%= image_path(tweet.user.profile_image_url_https.to_s.gsub('_normal','')) %>' alt="" style="width: 100%;height: 100%;">
                        </div>
                        <div class="timeline-panel">
                            <div class="timeline-heading">
                                <!-- Show user name -->
                                <h4> <%= tweet.user.name %></h4>
                                <h4 class="subheading"> <%= "@#{tweet.user.screen_name}"  %> </h4>
                            </div>
                            <div class="timeline-body">
                                <p class="text-muted"> <%= tweet.text%> </p>
                                <i class="fa fa-retweet"> <%= tweet.retweet_count %> </i>
                                <i class="fa fa-heart"> <%= tweet.favorite_count %> </i>                                        
                            </div>
                        </div>
                    </li>
                <% end %>
            </ul>
        </div>
    </div>
    

    【讨论】:

      猜你喜欢
      • 2011-06-19
      • 2013-03-15
      • 1970-01-01
      • 1970-01-01
      • 2012-09-09
      • 2012-02-23
      • 1970-01-01
      • 2011-07-24
      • 2018-07-03
      相关资源
      最近更新 更多