Twitter ::错误::禁止:创建状态时出错

时间:2017-03-01 07:55:15

标签: ruby-on-rails heroku twitter

我正在尝试从网络作业发送推文,以通知我的用户某些事件。

它在我的本地计算机上工作正常但是当部署到Heroku时,我在尝试使用媒体发推文时遇到以下错误:

Twitter::Error::Forbidden: Error creating status.
    from /app/vendor/bundle/ruby/2.2.0/gems/twitter-5.17.0/lib/twitter/rest/response/raise_error.rb:12:in `on_complete'
    from /app/vendor/bundle/ruby/2.2.0/gems/faraday-0.9.2/lib/faraday/response.rb:9:in `block in call'
    from /app/vendor/bundle/ruby/2.2.0/gems/faraday-0.9.2/lib/faraday/response.rb:57:in `on_complete'
    from /app/vendor/bundle/ruby/2.2.0/gems/faraday-0.9.2/lib/faraday/response.rb:8:in `call'
    from /app/vendor/bundle/ruby/2.2.0/gems/faraday-0.9.2/lib/faraday/request/url_encoded.rb:15:in `call'
    from /app/vendor/bundle/ruby/2.2.0/gems/faraday-0.9.2/lib/faraday/request/multipart.rb:14:in `call'
    from /app/vendor/bundle/ruby/2.2.0/gems/twitter-5.17.0/lib/twitter/rest/request/multipart_with_file.rb:21:in `call'
    from /app/vendor/bundle/ruby/2.2.0/gems/faraday-0.9.2/lib/faraday/rack_builder.rb:139:in `build_response'
    from /app/vendor/bundle/ruby/2.2.0/gems/faraday-0.9.2/lib/faraday/connection.rb:377:in `run_request'
    from /app/vendor/bundle/ruby/2.2.0/gems/faraday-0.9.2/lib/faraday/connection.rb:177:in `post'
    from /app/vendor/bundle/ruby/2.2.0/gems/twitter-5.17.0/lib/twitter/rest/request.rb:33:in `perform'
    from /app/vendor/bundle/ruby/2.2.0/gems/twitter-5.17.0/lib/twitter/rest/utils.rb:50:in `perform_request'
    from /app/vendor/bundle/ruby/2.2.0/gems/twitter-5.17.0/lib/twitter/rest/utils.rb:72:in `perform_request_with_object'
    from /app/vendor/bundle/ruby/2.2.0/gems/twitter-5.17.0/lib/twitter/rest/utils.rb:64:in `perform_post_with_object'
    from /app/vendor/bundle/ruby/2.2.0/gems/twitter-5.17.0/lib/twitter/rest/tweets.rb:233:in `update_with_media'

我可以发送纯文本推文,没有任何错误。关于这可能是什么原因的任何想法?

是否有一些限制Heroku阻止我发送图像?

发送推文的代码如下:

def send_tweet(company, data)
  file_name = ChartGenerator.build_company_chart(data)
  client.update_with_media(company_tweet_text(company), File.new(file_name))
end

def send_test_tweet
  client.update('Test tweet')
end

def client
  Twitter::REST::Client.new do |config|
    config.consumer_key        = ENV["TWITTER_CONSUMER_KEY"]
    config.consumer_secret     = ENV["TWITTER_CONSUMER_SECRET"]
    config.access_token        = ENV["TWITTER_ACCESS_TOKEN"]
    config.access_token_secret = ENV["TWITTER_ACCESS_TOKEN_SECRET"]
  end
end

send_test_tweet在Heroku和本地工作正常,send_tweet在本地工作,但不在Heroku上工作。

我通过控制台验证了ChartGenerator在Heroku上按预期工作。

生产需要一些法拉第设置吗? (我在堆栈跟踪中发现了法拉第)

0 个答案:

没有答案