我得到什麼似乎是從Twitter的成功響應:Twitter Oauth:oauth_token_secret在哪裏?
/auth/twitter/callback?oauth_token=somelongtoken&oauth_verifier=someverifier
但是沒有oauth_token_secret
那裏。我在哪裏得到它?
DETAIL
routes.rb
get '/auth/:provider', to: 'authorisations#authorise', :as => :new_auth
get '/auth/:provider/callback', to: 'authorisations#callback'
authorisations_controller.rb
def authorise
session[:user_id] = current_user.id
@authorisation = Authorisation.new
@authorisation.user_id = current_user.id
if auth_hash.provider == "facebook"
@authorisation.provider = auth_hash.provider
@authorisation.oauth_token = auth_hash.credentials.token
@authorisation.oauth_expires_at = Time.at(auth_hash.credentials.expires_at)
elsif params[:provider] == "twitter"
@authorisation.provider = params[:provider]
@authorisation.oauth_token = params[:oauth_token]
@authorisation.oauth_token_secret = params[:oauth_token_secret]
@authorisation.access_token = params[:oauth_verifier]
end
@authorisation.save!
end
def callback
session[:user_id] = current_user.id
@authorisation = Authorisation.new
@authorisation.user_id = current_user.id
if auth_hash.provider == "facebook"
@authorisation.provider = auth_hash.provider
@authorisation.oauth_token = auth_hash.credentials.token
@authorisation.oauth_expires_at = Time.at(auth_hash.credentials.expires_at)
elsif params[:provider] == "twitter"
@authorisation.provider = params[:provider]
@authorisation.oauth_token = params[:oauth_token]
@authorisation.oauth_token_secret = params[:oauth_token_secret]
@authorisation.access_token = params[:oauth_verifier]
end
@authorisation.save!
redirect_to root_url, notice: "#{current_user.name} and #{params[:provider].titlecase} have been linked."
end
def auth_hash
request.env['omniauth.auth']
end
documents_controller.rb
def twitter
session[:return_to] = request.referer
@document = Document.find(params[:id])
if @document.template.name == "Image"
@document.process_social_media
twitter_user.update_with_media("#{@document.remove_html(@document.components.first.body[0..100])}...", "#{root_url}temporary#{@document.temp_file_name}.jpg")
else
twitter_user.update("#{@document.remove_html(@document.components.first.body[0..100])}... #{root_url.gsub(/\/$/, '')}#{share_path(@document.user.ftp, @document)}")
end
redirect_to session[:return_to], notice: "#{@document.title} has been posted to Twitter."
end
def twitter_user
user = Twitter.configure do |config|
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
config.oauth_token = current_user.single_authorisation("twitter").oauth_token
config.oauth_token_secret = current_user.single_authorisation("twitter").oauth_token_secret
end
end
您是否使用所有必需的參數發出了request_token? –
有要求嗎?我只是在做Oauth的方式。將更新。 –