【问题标题】:Heroku Twitter api app deployment with Rails使用 Rails 部署 Heroku Twitter api 应用程序
【发布时间】:2021-08-18 11:09:21
【问题描述】:

总的来说,我是 Ruby 和 Rails 的新手,并且正在关注这个系列

https://gorails.com/episodes/rails-for-beginners-part-38-deploying-to-heroku

我有一个奇怪的问题,除了连接我的应用程序之外,一切似乎都正常

推特 API。

我尽一切努力连接成功,但似乎没有任何效果!

我将网站链接添加到 Twitter 开发者回调 url,它们是

https://jadwlh.herokuapp.com/

随着

https://jadwlh.herokuapp.com/auth/twitter/callback

两个都加了

API_KEY

API_SECRET

配置变量。

我什至在 Config Vars 中更改了 SECRET_KEY_BASE

到我的应用程序的凭据文件中提供的那个!

即使尝试了所有方法,当我尝试时仍然收到下图中显示的此消息

将我的应用程序与 Twitter Api 连接

routes.rb 文件

# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html

Rails.application.routes.draw do

  #GET /about
  get "about", to: "about#index"

  get "password", to: "passwords#edit", as: :edit_password
  patch "password", to: "passwords#update"

  get "sign_up", to: "registrations#new"
  post "sign_up", to: "registrations#create"

  delete "logout", to: "sessions#destroy"

  get "sign_in", to: "sessions#new"
  post "sign_in", to: "sessions#create"

  get "password/reset", to: "password_resets#new"
  post "password/reset", to: "password_resets#create"
  get "password/reset/edit", to: "password_resets#edit"
  patch "password/reset/edit", to: "password_resets#update"

  get "/auth/twitter/callback", to: "omniauth_callbacks#twitter"

  resources :twitter_accounts
  resources :tweets

  # get "/", to: "main#index"
  root to: "main#index"
end

应用程序日志

2021-05-31T06:15:04.415968+00:00 app[web.1]: [13f44544-8fd2-4348-8b08-1191ad53716b]   
2021-05-31T06:15:04.418156+00:00 heroku[router]: at=info method=HEAD path="/auth/failure?message=session_expired&strategy=twitter" host=jadwlh.herokuapp.com request_id=13f44544-8fd2-4348-8b08-1191ad53716b fwd="217.182.175.162" dyno=web.1 connect=0ms service=3ms status=404 bytes=180 protocol=https
2021-05-31T06:15:31.243002+00:00 app[web.1]: I, [2021-05-31T06:15:31.242901 #4]  INFO -- : [c5f8ff8c-58fa-439d-a9f3-e08047bc5aa8] Started POST "/auth/twitter" for 46.152.103.96 at 2021-05-31 06:15:31 +0000
2021-05-31T06:15:31.243645+00:00 app[web.1]: D, [2021-05-31T06:15:31.243583 #4] DEBUG -- omniauth: (twitter) Request phase initiated.
2021-05-31T06:15:31.388564+00:00 app[web.1]: E, [2021-05-31T06:15:31.388453 #4] ERROR -- omniauth: (twitter) Authentication failure! 400 Bad Request: OAuth::Unauthorized, 400 Bad Request
2021-05-31T06:15:31.390962+00:00 heroku[router]: at=info method=POST path="/auth/twitter" host=jadwlh.herokuapp.com request_id=c5f8ff8c-58fa-439d-a9f3-e08047bc5aa8 fwd="46.152.103.96" dyno=web.1 connect=1ms service=150ms status=302 bytes=834 protocol=https
2021-05-31T06:15:31.574904+00:00 heroku[router]: at=info method=GET path="/auth/failure?message=400+Bad+Request&strategy=twitter" host=jadwlh.herokuapp.com request_id=3adfd6f0-58b9-47c3-ab04-017161a56e18 fwd="46.152.103.96" dyno=web.1 connect=1ms service=6ms status=404 bytes=1902 protocol=https
2021-05-31T06:15:31.571195+00:00 app[web.1]: I, [2021-05-31T06:15:31.571067 #4]  INFO -- : [3adfd6f0-58b9-47c3-ab04-017161a56e18] Started GET "/auth/failure?message=400+Bad+Request&strategy=twitter" for 46.152.103.96 at 2021-05-31 06:15:31 +0000
2021-05-31T06:15:31.572790+00:00 app[web.1]: F, [2021-05-31T06:15:31.572717 #4] FATAL -- : [3adfd6f0-58b9-47c3-ab04-017161a56e18]   
2021-05-31T06:15:31.572791+00:00 app[web.1]: [3adfd6f0-58b9-47c3-ab04-017161a56e18] ActionController::RoutingError (No route matches [GET] "/auth/failure"):
2021-05-31T06:15:31.572792+00:00 app[web.1]: [3adfd6f0-58b9-47c3-ab04-017161a56e18]   

谢谢你:)

【问题讨论】:

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


    【解决方案1】:

    我找到了解决办法。

    它只是在复制 master.key 并按照下面的说明替换它!

    heroku config:set RAILS_MASTER_KEY="copy and paste here config/master.key "
    

    How to get rails master.key after upgrading to rails 5.2

    【讨论】:

      猜你喜欢
      • 2018-08-06
      • 1970-01-01
      • 2015-12-25
      • 2014-08-08
      • 2017-08-22
      • 2018-08-12
      • 2015-03-04
      • 2013-01-08
      • 1970-01-01
      相关资源
      最近更新 更多