我正在尝试从Rails的网站中获取我的Facebook帐户中的Facebook页面列表。从我的应用程序中从Facebook授权时,我在其中添加了protect_from_forgery with: :reset_session
,但收到错误Error Authorizing. Please try again later. Csrf detected
。这是一个随机错误,在我的计算机上的任何浏览器上都不会发生。但是,某些用户报告他们正在收到此错误。如何重现此错误以及如何解决?
我的授权控制器中有以下代码,
class AuthorizationsController < BusinessDashboardController
def setup
if params[:provider].to_s.casecmp(Authorization::FACEBOOK).zero?
if params[:activity] && params[:activity] == "bot"
# request.env['omniauth.strategy'].options[:scope] = "email,manage_pages,publish_pages,pages_messaging,pages_messaging_phone_number"
request.env['omniauth.strategy'].options[:callback_url] = "#{request.base_url}/auth/facebook/callback?activity=bot"
request.env['omniauth.strategy'].options[:client_id] = GlobalConfiguration.bot[:app_id]
request.env['omniauth.strategy'].options[:client_secret] = GlobalConfiguration.bot[:app_secret]
end
end
render text: "Omniauth setup phase.", status: 404
end
end
在BusinessDashboardsController中,
class BusinessDashboardController < ApplicationController
protect_from_forgery with: :reset_session
end
在Gemfile中,
gem 'facebook-messenger', '~> 1.0.0'