继续获取Ruby Twitter :: Error :: Forbidden

时间:2015-04-15 20:59:16

标签: ruby windows loops twitter status

我从文本文件中提取推文,并按时间间隔发推文。随着第一条推文发布,一切都很好。当下次推文发布的时间我得到的错误是:

enter image description here

我拿到了四把钥匙,但是我可以随时更新它们或获得新钥匙......以下是我使用的代码:

require 'Twitter'

client = Twitter::REST::Client.new do |config|
  config.consumer_key = "..."
  config.consumer_secret = "..."
  config.access_token = "..."
  config.access_token_secret = "..."
end


def repeat_every(interval)
  loop do
    start_time = Time.now
    yield
    elapsed = Time.now - start_time
    sleep([interval - elapsed, 0].max)
  end
end


blog_post = []
tweet_img = []


def post 
    client = Twitter::REST::Client.new do |config|
        config.consumer_key = "..."
        config.consumer_secret = "..."
        config.access_token = "..."
        config.access_token_secret = "..."
    end
  File.open("tweets.txt") do |line|
    line.each do |item|
      tweets = item
      puts tweets
      client.update("#{tweets}").to_s
      sleep((rand*1800 +900).to_i)
    end
  end
end


repeat_every(81000){
    post
}

2 个答案:

答案 0 :(得分:0)

require 'Twitter'

def repeat_every(interval)
  loop do
    start_time = Time.now
    yield
    elapsed = Time.now - start_time
    sleep([interval - elapsed, 0].max)
  end
end


def post 
    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.open("tweets.txt") do |line|
    line.each_line do |item|
      tweets = item
      puts tweets
      client.update("#{tweets}")
      sleep((rand*10 + 10).to_i)
    end
  end

end


repeat_every(81000){
    post
}

答案 1 :(得分:0)

在第二行插入此代码

OpenSSL :: SSL :: VERIFY_PEER = OpenSSL :: SSL :: VERIFY_NONE