我收到以下URL信息,需要在rails中解析它。我已经检查过请求和参数,但它不在那里。在rails中解析#uris
“#”字符看起来似乎有些东西。
这里的网址:
http://foo.bar.me/whoo#access_token=131268096888809%7C2.5BRBl_qt4xJ08n88ycbpZg__.3600.1276880400-100001151606930%7C0kJ1K-qoGBbDoGbLx6s4z5UEaxM.
感谢任何指针。
我收到以下URL信息,需要在rails中解析它。我已经检查过请求和参数,但它不在那里。在rails中解析#uris
“#”字符看起来似乎有些东西。
这里的网址:
http://foo.bar.me/whoo#access_token=131268096888809%7C2.5BRBl_qt4xJ08n88ycbpZg__.3600.1276880400-100001151606930%7C0kJ1K-qoGBbDoGbLx6s4z5UEaxM.
感谢任何指针。
由于浏览器未将其发送到服务器,您将无法访问'#'字符后面的部分。尽管你可以在客户端使用它。
看来你正在尝试使用不是你真正想要的javascript based authentication。
我没有使用此oauth2库的任何问题。那么你只需要在你的回调行动中检查params[:code]
。
UPDATE:
这是我在实验中使用与新的Facebook图形API代码的简化版本:
# Accessible as facebook_url:
# routes.rb: map.facebook '/facebook', :controller => 'facebook', :action => 'index'
def index
oauth2 = OAuth2::Client.new(FB_API_KEY, FB_API_SECRET, :site => 'https://graph.facebook.com')
if current_user.facebook_token
# The user is already authenticated
fb = OAuth2::AccessToken.new(oauth2, current_user.facebook_sid)
result = JSON.parse(fb.get('/me'))
elsif params[:code]
# Here we get the access token from facebook
fb = oauth2.web_server.get_access_token(params[:code], :redirect_uri => facebook_url)
result = JSON.parse(fb.get('/me'))
current_user.facebook_id = result["id"]
current_user.facebook_token = fb.token.to_s
current_user.save
else
# The user is visiting this page for the first time. We redirect him to facebook
redirect_to oauth2.web_server.authorize_url(:redirect_uri => facebook_url, :scope => 'read_stream,publish_stream,offline_access')
end
end
你并不真正需要的任何东西为它工作。
很好的答案,非常感谢!澄清事情:它看起来像apache mod_rewrite去掉“#”。 – z3cko 2010-06-18 18:27:39
它没有被mod_rewrite剥离,#部分永远不会到达服务器,它仅由客户端浏览器解释。 – 2010-06-18 18:53:49
请更明确。你如何收到这个网址?你使用什么代码?究竟发生了什么问题?等等...(另外,不需要亵渎...) – thomasfedb 2010-06-18 15:35:35
我正在尝试为http://appsbiddington.wordpress.com/2010/04/23/facebook- graph-api-getting-access-token/- 我按照概述重定向,但无法访问令牌,因为它位于# – z3cko 2010-06-18 15:46:29
之后,如果您从wordpress获得此URL,则是wordpress问题。因为不像这样渲染access_token。 – shingara 2010-06-18 15:59:53