[英]ruby tweet line from text file
我的代碼不會在每個時間間隔從文件中發送鳴叫,它只會在終端中顯示,而不會在Twitter上顯示。 我還試圖循環它,以便一旦使用file.length完成它的重復。 謝謝你的幫助。
require 'Twitter'
client = Twitter::REST::Client.new do |config|
config.consumer_key = "..."
config.consumer_secret = "..."
config.access_token = "..."
config.access_token_secret = "..."
end
blog_post = []
tweet_img = []
def post
File.open("tweets.txt") do rand |line|
line.each do |item|
tweets = item.chomp.split("\n")
#while client.update("#{}")
puts tweets
sleep(30)
#end
#puts blog_post.to_s, "\n\n"
end
end
end
puts client.update("#{post}").text
require 'Twitter'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
client = Twitter::REST::Client.new do |config|
config.consumer_key = "xxxx"
config.consumer_secret = "xxxx"
config.access_token = "xxxx"
config.access_token_secret = "xxxx"
end
file = File.open("tweets.txt")
ary = []
i = 0
file.each_line do |line|
ary[i] = line.chomp
i += 1
end
file.close
j = 0
i.times do
client.update("#{ary[j]}")
j += 1
sleep 10
end
您打給Twitter的電話:
client.update("#{post}").text
在循環之外,因此僅被調用一次。 如果您希望每一行都使用它,則應為:
def post
File.open("tweets.txt") do rand |line|
line.each do |item|
tweets = item.chomp.split("\n")
puts tweets
client.update("#{tweets}").text
sleep(30)
end
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.