【发布时间】:2017-08-06 18:35:51
【问题描述】:
我正在使用 Twitter gem 创建一个项目,需要过滤从mentions_timeline 收到的推文。
我想过通过阅读推文文本的几个if 语句进行过滤:
require 'sinatra'
require 'twitter'
require 'sinatra/reloader'
include ERB::Util
before do
config = {
:consumer_key => 'xxx',
:consumer_secret => 'xxx',
:access_token => 'xxx',
:access_token_secret => 'xxx'
}
@client = Twitter::REST::Client.new(config)
end
get '/order' do
@tweets = @client.mentions_timeline
@collect_tweets = Array.new
@delivery_tweets = Array.new
@tweets.each do |tweet|
if (tweet.text.include? "order" && tweet.text.include? "collect")
@collect_tweets.push(tweet)
elsif (tweet.text.include? "order" && tweet.text.include? "delivery")
@delivery_tweets.push(tweet)
end
erb :order
end
但它不会起作用。
我收到此错误:
/Users/me/Projects/team-13/order.rb:23: syntax error, unexpected tSTRING_BEG, expecting ')' rder" && tweet.text.include? "collect") ^ /Users/me/Projects/team-13/order.rb:25: syntax error, unexpected tSTRING_BEG, expecting ')' rder" && tweet.text.include? "delivery") ^ /Users/me/Projects/team-13/order.rb:30: syntax error, unexpected end-of-input, expecting keyword_end
【问题讨论】:
-
请阅读“minimal reproducible example”。我们只需要足够的代码来运行 和测试以复制问题。我们还需要最少的支持数据来帮助证明这一点。否则,它会浪费我们的时间。 SO 不是您提到的“帮助我”网站,但为了帮助他人,我们需要某些东西。
-
为了复制问题,您需要拥有 twitter 密钥,我显然不会在这里发布。我只是想知道是否有人对 ruby 有更多的专业知识,而不是我所拥有的小知识,是否会看到一个可能是问题的大语法错误。无论如何,在我没有具体说明问题本身的意义上,你是对的。谢谢你告诉我,我会编辑帖子;)