【问题标题】:Rails - Twitter::Error::BadRequest (Bad Authentication data) - After Deploying to HerokuRails - Twitter::Error::BadRequest(错误的身份验证数据) - 部署到 Heroku 之后
【发布时间】:2012-11-03 15:03:45
【问题描述】:

在我的应用中,我使用以下代码为用户提供推文:

       if twitter = current_user.authentications.find_by_provider("twitter")
        Twitter.configure do |tw|
          tw.consumer_key = "6jaqMt7kE9iVxh8hX0mmtQ"
          tw.consumer_secret = "5ZIydxRBFfEJxc2EzedahIxoeO8g1hZCQVqZFtWWNM"
          tw.oauth_token = twitter.token
          tw.oauth_token_secret = twitter.token_secret
        end
        Twitter.update(params[:tweet])

它在我的本地主机中运行良好。但是现在我已经将我的应用程序部署到 heroku,并且我正在尝试发送推文,但在 heroku 日志中它说:

2012-11-15T01:30:32+00:00 app[web.1]: Completed 500 Internal Server Error in 494ms
2012-11-15T01:30:32+00:00 app[web.1]: 
2012-11-15T01:30:32+00:00 app[web.1]: Twitter::Error::BadRequest (Bad Authentication data):
2012-11-15T01:30:32+00:00 app[web.1]: 
2012-11-15T01:30:32+00:00 app[web.1]: 
2012-11-15T01:30:32+00:00 app[web.1]:   app/controllers/posts_controller.rb:12:in `create'

我应该怎么做才能解决这个问题?

谢谢。

【问题讨论】:

    标签: ruby-on-rails twitter heroku twitter-oauth


    【解决方案1】:

    两件事:

    1. 在您注册的 Twitter 应用程序的设置中,将您的回调 URL 更新到您的生产服务器位置。

    2. 如果您使用的是 herokuapp.com 的子域,您猜怎么着,您正处于对 Twitter 的大量其他 API 请求的池中。 Proxy your API requests through Apigee。

    3. 初始化然后通过控制台迁移 Heroku 上的数据库:

      heroku run rake db:setup

      heroku run rake db:migrate

    (通常只是 rake db:migrate 工作,但在这种情况下我必须同时做)

    来源于Twitter dev discussions

    【讨论】:

      【解决方案2】:

      我已经弄清楚了 Twitter 身份验证,并根据我的经验写了一个教程:http://www.orhancanceylan.com/rails-twitter-and-facebook-authentications-with-omniauth-and-devise/

      【讨论】:

      • 请重新发布/编辑您的答案,以便将答案的重点发布在 this 网站上。
      猜你喜欢
      • 2015-06-01
      • 2013-06-30
      • 1970-01-01
      • 1970-01-01
      • 2012-11-04
      • 2012-09-22
      • 2012-11-24
      • 2017-10-24
      • 2012-05-04
      相关资源
      最近更新 更多