【问题标题】:Gem 'twitter'. Parsing returns only part of the tweet宝石“推特”。解析只返回推文的一部分
【发布时间】:2018-07-04 03:19:10
【问题描述】:

我正在使用 twitter gem。请告诉我为什么我在解析时只得到一部分推文?看看 (live demo)。

例如:

Yeah, we don't want to hear from you. You've been yapping away for a million years. And by the w… 
Then, ‘for balance’ you need to also clearly and repe…
You stated as fact that there would be a #Brexit dividend,…

这是我的代码:

控制器

@arr = []
client.search("@#{params[:twitter_acc]}", result_type: "recent")
      .take(params[:number_of_tweets].to_i)
      .collect do |tweet|
  @arr << tweet
            .text
            .gsub("@#{params[:twitter_acc]}", "")
            .gsub("RT :", "")
            .gsub("RT", "")
end

查看

<% @arr.uniq.each do |line| %>
  <%= line %><br>
<% end %>

我该如何解决这个问题? 有什么想法吗?

更新

Tweet_parser. Result screenshot

【问题讨论】:

  • params[:number_of_tweets] 长什么样子?
  • @dinjas:我假设"30",来自在线演示。
  • 是的。 30. 但我担心推文有时会以点结尾(...)。
  • 你确定这些点不在官方推文中吗?有时人们这样做是为了他们可以在多条推文中写一些东西....
  • 像这样.....

标签: ruby-on-rails ruby twitter


【解决方案1】:

试试这个:

@arr = []
client.search("@#{params[:twitter_acc]}", result_type: "recent", tweet_mode: "extended")
      .take(params[:number_of_tweets].to_i)
      .collect do |tweet|
  @arr << tweet
            .full_text
            .gsub("@#{params[:twitter_acc]}", "")
            .gsub("RT :", "")
            .gsub("RT", "")
end

【讨论】:

  • 看看我的更新。很抱歉,但这不起作用。
  • 安迪,tweet_mode: "extended" 不起作用。有什么想法吗?
  • 这很奇怪 - 根据这个 Github 问题github.com/sferik/twitter/issues/880#issuecomment-358485714 我认为支持 tweet_mode 扩展。这可能是我建议访问文本的方式?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-29
  • 2012-12-10
  • 1970-01-01
  • 1970-01-01
  • 2011-02-10
  • 1970-01-01
相关资源
最近更新 更多