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