4

在我的应用程序中,我为用户提供了使用以下代码发送推文:

       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'

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

谢谢。

4

2 回答 2

0

两件事情:

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

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

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

    heroku run rake db:setup

    heroku run rake db:migrate

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

来自Twitter 开发讨论

于 2013-02-03T13:25:40.750 回答
-1

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

于 2012-11-21T01:40:15.147 回答