Ruby Twitter,检索完整的推文文本

Ruby Twitter, Retrieving Full Tweet Text

我正在使用 Ruby Twitter gem 检索推文的全文。

我第一次尝试这个,正如你所看到的,文本被截断了。

[5] pry(main)> t = client.status(782845350918971393)
=> #<Twitter::Tweet id=782845350918971393>
[6] pry(main)> t.text
=> "A #Gameofthrones fan? Our #earlybird Dublin starter will get you 
touring the GOT location in 2017
#traveldealls… (SHORTENED URL WAS HERE)"

然后我试了这个:

[2] pry(main)> t = client.status(782845350918971393, tweet_mode: 'extended')
=> #<Twitter::Tweet id=782845350918971393>
[3] pry(main)> t.full_text
=>
[4] pry(main)> t.text
=>

当我使用 tweet_mode: 'extended' 选项时,正文和全文都是空的。

我也尝试编辑发出请求的 gem 的位,响应是一样的。 perform_get_with_object("/1.1/statuses/show/#{extract_id(tweet)}.json?tweet_mode=extended", options, Twitter::Tweet)

如有任何帮助,我们将不胜感激。

这是我发现有用的解决方法:

Below is the way I am handling this issue ATM. Seems to be working. I am using both Streaming (with Tweetstream) and REST APIs.

status = @client.status(1234567890, tweet_mode: "extended")

if status.truncated? && status.attrs[:extended_tweet]
  # Streaming API, and REST API default
  t = status.attrs[:extended_tweet][:full_text]
else
  # REST API with extended mode, or untruncated text in Streaming API
  t = status.attrs[:text] || status.attrs[:full_text]
end

来自https://github.com/sferik/twitter/pull/848#issuecomment-329425006