想要通过Twitter API抓一堆推文,作为输出我得到cURL命令,就像那样
curl --get 'https://api.twitter.com/1.1/search/tweets.json' --data 'q=football' --header 'Authorization: OAuth oauth_consumer_key="**hidden**", oauth_nonce="**hidden**", oauth_signature="**hidden**", oauth_signature_method="HMAC-SHA1", oauth_timestamp="**hidden**", oauth_token="**hidden**", oauth_version="1.0"' --verbose
我的问题是,有没有办法在Ruby脚本中使用此命令来删除推文?
答案 0 :(得分:1)
使用这里提供的Twitter gem http://rdoc.info/gems/twitter和以下代码,您可以从ruby脚本中获取所有推文。
require 'twitter'
client = Twitter::REST::Client.new do |config|
config.consumer_key ="hidden"
config.consumer_secret ="hidden"
config.access_token ="hidden"
config.access_token_secret ="hidden"
end
client.search("football").collect do |tweet|
puts tweet.text
end
答案 1 :(得分:0)
你可以将它包装在反引号中,并从任何unix(如)命令
中获取输出script.rb
cmd=`echo 'hello world'`
puts cmd
ouptput:你好世界
答案 2 :(得分:0)