Twitter::Error::Unauthorized in PostsController#create - Invalid or expired token

Deadly 提交于 2019-12-01 12:37:16

You need something like '@twitter_user.update'. For each twitter user you create with 'Twitter::Client.new' you have to provide omniauth's token and secret(like you do it in 'user.rb' model)

class PostsController < ApplicationController
  def create
    # get twitter user. Feel free to change it depending on your app
    @twitter_user = User.twitter
    @twitter_user.update(@post.content)
  end
end

I think the current "token" and "secret" in the "authentications" table you are using have been expired.

  • You can simply try deleting all rows in the "authentications" table, then signing in with twitter account again and see whether it is working.
  • Or try setting a breakpoint just after the codes of user getting authenticated with twitter account, then just executing tweet posting lines once you manually set the "token" and "secret" with returned authentication information: ["credentials"]["token"] and ["credential"]["token"]. I think the tweet will be posted.

If it's still not working, you'd better show other related codes like session controller as well. The whole picture of your authentication flow will be more helpful to figure the problem out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!