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

标签 ruby api twitter rubygems

我正在使用 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

关于Ruby Twitter,检索完整的推文文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47383617/

相关文章:

ruby - 获取在 Ruby 中打印的最后一行

ruby-on-rails - 如何修复 AWS Elastic beanstalk Rails Assets 预编译上的文件权限错误?

c++ - tesseract-ocr 如何包含 baseapi.h

javascript - 如何检索 github graphql api 上的多个问题(使用 javascript)?

node.js - 如何使用 Twitter 通过地理编码进行搜索?

python - Python 中的 DynamoDB 查询(使用 GroupBy 进行计数)

c++ - 如何开始使用 twitCurl?

ruby - 在 Padrino application.haml 模板中选择性地使用yield_content

ruby - Nokogiri 和 Mechanize 问题

api - 在 youtube-api 中下载自己的视频