Koala :: Facebook :: AuthenticationError - 类型:OAuthException,代码:2500,消息

时间:2015-11-18 11:31:46

标签: ruby-on-rails ruby facebook oauth koala-gem

我正在尝试设置一个项目。一切都很好,但这个错误一直在提示,似乎没有任何帮助。这是我点击网址时的日志。

Koala::Facebook::AuthenticationError - type: OAuthException, code: 2500, message: An active access token must be used to query information about the current user. [HTTP 400]:
koala (2.2.0) lib/koala/api/graph_api.rb:515:in `block in graph_call'
koala (2.2.0) lib/koala/api.rb:80:in `api'
koala (2.2.0) lib/koala/api/graph_api.rb:513:in `graph_call'
koala (2.2.0) lib/koala/api/graph_api.rb:115:in `get_connection'
() home/yogesh/Desktop/jugojuice/jugojuice/app/controllers/pages_controller.rb:98:in `show'
() home/yogesh/Desktop/jugojuice/jugojuice/app/controllers/pages_controller.rb:64:in `home'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:308:in `block (2 levels) in halting'
() home/yogesh/.rvm/gems/ruby-2.2.3/bundler/gems/route_translator-f00b46885426/lib/route_translator/extensions/action_controller.rb:20:in `set_locale_from_url'
activesupport (4.2.0) lib/active_support/callbacks.rb:427:in `block in make_lambda'
activesupport (4.2.0) lib/active_support/callbacks.rb:307:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
xray-rails (0.1.16) lib/xray/middleware.rb:37:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.0) lib/rack/etag.rb:24:in `call'
rack (1.6.0) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.0) lib/rack/head.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.0) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.0) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
rack-livereload (0.3.15) lib/rack/livereload.rb:23:in `_call'
rack-livereload (0.3.15) lib/rack/livereload.rb:14:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
rack (1.6.0) lib/rack/content_length.rb:15:in `call'
rack (1.6.0) lib/rack/handler/webrick.rb:89:in `service'
 () home/yogesh/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
 () home/yogesh/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
 () home/yogesh/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
logging (1.8.2) lib/logging/diagnostic_context.rb:323:in `block in create_with_logging_context'



Started POST "/__better_errors/329b87011a8e5497/variables" for ::1 at 2015-11-18 16:48:21 +0530

我在pages_controller.rb中的代码

class PagesController < ApplicationController

layout :determine_layout
before_filter :cms_setup, :only => [:show,  :sitemap, :search]
before_filter :set_locale
helper_method :transformed_content

def parse_facebook_cookies
@facebook_cookies = Koala::Facebook::OAuth.new.get_user_info_from_cookie(cookies)
end

def sitemap
@page = Page.friendly.find("sitemap")
@subnav_pages = nil
end

def search
@page = Page.friendly.find("search")
@section = @page
@pages=Page.nested_set
@search = Sunspot.search([Cms::Page, Cms::Asset, Product, City, Location]) do
  fulltext  params[:terms] do
    fields  "title_#{I18n.locale}".to_sym, "content_#{I18n.locale}".to_sym, "description_#{I18n.locale}".to_sym, "address_#{I18n.locale}".to_sym
  end
end
@results = @search.results
end

def cms_update
page = Page.find(params[:id])
region = Cms::Region.find(params[:region_id])
asset =  Cms::Asset.find(params[:asset_id]) if params[:asset_id] && !params[:asset_id].blank?
# Update page
if asset
  #asset.update_column(:content,  params[:content])
  if asset.content != params[:content]
    asset.content = params[:content]
    asset.save!
  end
  expire_fragment(["page_#{page.id}_region_#{region.id}_asset_#{asset.id}"])
  else
  asset = Cms::Asset.new(:content => params[:content], :name => "#{page.title} - #{region.name}")
  asset.save
  end

pra = Cms::PageRegionAsset.find_or_initialize_by(page_id: page.id, region_id: region.id, asset_id: asset.id) unless asset.nil?

unless params[:content].blank?
  pra.save!
end

render text: ""
end


def home
response.headers.delete "X-Frame-Options"
@page = Page.root
get_site_pages
get_main_nav
get_subnav
@slides = Slide.visible.in_order
@newsletter_signup = NewsletterSignup.new
show
render "show"
end

def show
response.headers.delete "X-Frame-Options"
if @page.redirect_page_id.nil?
  #get page template and regions
  @template = @page.template
  @regions = @template.regions
  if @page.product_lines.any?
    @product_line = @page.product_lines.first
  end
  if is_editing?
    @page_content = HashWithIndifferentAccess[:regions => @regions.map { |r| {:placeholder => r.placeholder, :name => r.name, :id => r.id, :assets => r.serialized_assets_for(@page)}}.flatten]
  else
    @page_content = HashWithIndifferentAccess[:regions => @regions.map { |r|
                                                {:placeholder => r.placeholder, :name => r.name, :id => r.id, :assets => r.serialized_assets_for(@page)}
                                              }.flatten]
  end
  @cms_assets = @page.page_region_assets.order(position: :asc)
else
  unless @page.redirect_page_id.nil?
    @page = Page.find(@page.redirect_page_id)
    redirect_to @page.menu_url and return
  end
end
@instagram = Instagram.user_recent_media("2502342425320", {:count => 4})
@oauth = Koala::Facebook::OAuth.new("15239926112542342322478", "fc960a1a044492431aer35qafsd44a42c9c47990ef9b", "http://localhost:3000/")
@authtoken = @oauth.get_app_access_token
# generate authenticating URL
@graph = Koala::Facebook::API.new("1523992323611252478|1iBWrcRsYSBsISfsyUoNSmm_opxrI")
# @friends = @graph.get_connections("me", "friends")
# @profile = @graph.get_object("me")
@feed = @graph.get_connections("me", "feed")
end

def render_404
respond_to do |format|
  format.html { render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found }
  format.xml  { head :not_found }
  format.any  { head :not_found }
end
end

private
def determine_layout
@page.template.file_name
end

def get_main_nav
@main_nav_items = Page.main_nav
end

def get_subnav
@subnav_pages = @page.subnav_pages
end

def get_site_pages
@site_pages = Page.nested_set.visible
end

def cms_setup
#render text: params.inspect and return
if params[:path].nil?
  @page = Page.root
else
  @page = Page.find_by_slug(params[:id]) if params[:id]
  @page ||= Page.friendly.find(params[:path]) if params[:path]
  @page ||= Page.root unless params[:path]
  @page ||= Page.find_by(slug: params[:path].match(/[^\/]+$/)[0]) if params[:path]
  @page ||= Page.find_by_slug("404")
  if @page.nil?
    #render text: params.inspect and return
    render_404 and return
    #page_not_found
    redirect_to "/404" and return
  end
end
@section = @page if @page.depth == 1
@section ||= @page.ancestors.select{|p| p.depth == 1}.first if @page.depth > 1
get_main_nav
get_subnav
end

def transformed_content(content)
frag = Nokogiri::HTML::fragment(content) #this gets us the regions content in a nodset
snippets = frag.css("div.cms-snippet")
dynamic_snippets = frag.xpath('descendant::div[@data-snippettype="dynamic"]')
dynamic_snippets.each do |ds|
  object_class = ds.xpath("@data-objectclass")
  object_id = ds.xpath("@data-objectid").first.value
  snippet_partial = "/#{object_class.to_s.pluralize}/instance.html.haml"
  ds.content = "" #zero out the content and replace it with a rendered partial
  ds << (raw render :partial => snippet_partial, :locals => {:object_id => object_id}).to_s
end
frag
end

def page_params
params.require(:page).permit!
end

def page_not_found
raise ActionController::RoutingError.new('Not Found')
end

def set_locale
unless request.path.include?("/api")
  @locale = params[:locale]
  @locale ||= cookies[:locale]
  @locale ||= I18n.default_locale

  I18n.locale = @locale


  if params[:locale].blank?
    if cookies[:locale].blank?
      redirect_to "/#{I18n.default_locale.to_s}#{request.path_info}" unless request.path.include?("/admin")
    else
      redirect_to "/#{cookies[:locale].to_s}#{request.path_info}" unless request.path.include?("/admin")
    end
  end
  cookies[:locale] = I18n.locale
  if request.path.include?("/admin")
    I18n.locale = :en
  end
  end
  end
  end

如果有人告诉我这里有什么问题,我将非常感激。

1 个答案:

答案 0 :(得分:1)

正如@techdreams所评论的那样,错误是您正在使用的访问令牌,无效。查看您的代码似乎是从cookie获取访问令牌。请记住,如果用户退出Facebook或更改他/她的密码,访问令牌可能会变得无效,因此您总是在应用程序中实现“刷新令牌”,这基本上会再次提示登录对话框获取一个新的令牌。如果用户已经批准了您的应用程序,则此过程对他/她是透明的,他们将不会再次看到该对话框。