我試圖通過Facebook進行身份驗證,並得到以下錯誤消息鐵軌(考拉:: Facebook的:: AuthenticationError) - 試圖訪問配置文件OAuthException,代碼:190,消息:格式不正確的訪問令牌
考拉:: Facebook的:: AuthenticationError在AuthenticationsController#菜單 類型:OAuthException,代碼:190,消息:格式錯誤的接入令牌AQBiaE1v-pbSitzgNirHKSm7zNp3XoLAeHsvlFB626lARPBQCN98SBgIczjoRj3h8RQSVunm8gu-fHbO3H8-_9Ef9a5Lt00ixQ-wgum9p9FM5xN3WUvgc2BSyy1it2G4XlHNbQuwKYvsN-_7juH2NSXxMZmpaXh4qjjm13HWIjkYBWuyTIuJTJ7yUc97XixSMJtDbIIEBXfK52m_zIBTKvA4m8IoTOHDDoloeIhmARrGlMCmQG_vWZSMc ..(由作者刪除最後字符)[HTTP 400]
這是我的軌道控制器顯示錯誤的代碼。基本上登錄似乎工作。但是當我嘗試通過@graph.get_object("me")
訪問我的配置文件時,令牌不被接受。
class AuthenticationsController < ApplicationController
APP_ID="1234"
APP_SECRET="1234"
APP_CODE="XXXX"
SITE_URL="http://local.myapp.com:3000/"
def index
if session['access_token']
@face='Logged in -> <a href="authentications/logout">Logout</a>'
@graph = Koala::Facebook::API.new(session["access_token"])
else
@face='<a href="authentications/login">Login</a>'
end
end
def login
session['oauth'] = Koala::Facebook::OAuth.new(APP_ID, APP_SECRET, SITE_URL + 'authentications/callback')
redirect_to session['oauth'].url_for_oauth_code()
end
def logout
session['oauth'] = nil
session['access_token'] = nil
redirect_to '/'
end
def callback
session['access_token'] = params["code"]
redirect_to '/authentications/menu'
end
def menu
@ok="Hi!"
if session['access_token']
@face='Logged in -> <a href="/authentications/logout">Logout</a>'
@graph = Koala::Facebook::GraphAPI.new(session["access_token"])
## LEADS TO ERROR
@graph.get_object("me")
else
@face='<a href="/authentications/login">Login</a>'
end
end
end
而這個代碼使用sinatra的另一個例子正在工作。
#let Bundler handle all requires
require 'bundler'
require 'uri'
Bundler.require(:default)
# register your app at facebook to get those infos
APP_ID = 1234
APP_SECRET = '1234'
class SimpleRubyFacebookExample < Sinatra::Application
use Rack::Session::Cookie, secret: 'this_adfkaTGDGHDHJJJksk_0898932311_secret'
get '/' do
if session['access_token']
'You are logged in! <a href="/logout">Logout</a>'
@graph = Koala::Facebook::API.new(session["access_token"])
user = @graph.get_object("me")
feed = @graph.get_connections("me", "feed", {:limit => 999})
else
'Logout successful <br> Click to login <a href="/login">Login</a>'
end
end
get '/login' do
session['oauth'] = Koala::Facebook::OAuth.new(APP_ID, APP_SECRET, "#{request.base_url}/callback")
redirect session['oauth'].url_for_oauth_code(scope: "read_mailbox,read_stream")
end
get '/logout' do
session['oauth'] = nil
session['access_token'] = nil
redirect '/'
end
get '/callback' do
session['access_token'] = session['oauth'].get_access_token(params[:code])
redirect '/'
end
end
我的控制器/我的令牌有什麼問題?我輸出到控制檯,它似乎是好的。任何有用的提示表示讚賞!
當我使用https://developers.facebook.com/tools/explorer/上生成的修復access_token時,它正在工作,所以我想我會以某種方式得到一個錯誤的標記。 – Christian 2014-10-10 09:12:13