简体   繁体   English

Rails-Twitter :: Error :: BadRequest(错误身份验证数据)-部署到Heroku之后

[英]Rails - Twitter::Error::BadRequest (Bad Authentication data) - After Deploying to Heroku

In my app, I'm providing users to tweet with the following code: 在我的应用中,我为用户提供了以下代码:

       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])

It works well in my localhost. 它在我的本地主机上运行良好。 However now I've deployed my app to heroku, and I'm trying to send tweets, but in heroku logs it says: 但是现在我已经将我的应用程序部署到了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'

What should I do to solve this problem ? 我该怎么做才能解决这个问题?

Thanks. 谢谢。

Two things: 两件事情:

  1. Update your callback URL to your production server location, in your registered Twitter application's settings. 在已注册的Twitter应用程序设置中,将回调URL更新到生产服务器位置。

  2. If you're using a subdomain of herokuapp.com, guess what, you're in a pool of a bazillion other API requests to Twitter. 如果您使用的是herokuapp.com的子域,请猜猜是什么,您在Twitter中的其他API请求数量不计其数。 Proxy your API requests through Apigee . 通过Apigee代理您的API请求

  3. Initialize then migrate your database on Heroku through your console: 初始化然后通过控制台在Heroku上迁移数据库:

    heroku run rake db:setup

    heroku run rake db:migrate

(normally just rake db:migrate works, but I had to do both in this case) (通常只是rake db:migrate起作用,但在这种情况下我必须同时做这两项)

Sourced from the Twitter dev discussions 源自Twitter开发者讨论

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM