使用有效的Facebook App调用FB.getLoginStatus时,响应状态始终未知.确切的回答是{authResponse:undefined,status:"unknown"}.
<html>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function(){
FB.init({ appId:'1484134468466778', status:true, cookie:true, xfbml:true});
FB.getLoginStatus(function(response){
console.log(response);
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
示例网址:http: //media.tuentifotos.com/simple_test.html
这是Facebook App Settings的屏幕截图.

我一直在为我的rails应用程序设置facebook身份验证,在测试时,在使用我的facebook帐户登录后,我不断收到此错误:
OAuth2::Error:
{"error":{"message":"This authorization code has been used.","type":"OAuthException","code":100}}
Run Code Online (Sandbox Code Playgroud)
我不确定从哪里开始,但似乎无法在网上找到任何其他内容.任何指导将不胜感激,很高兴提供更多信息,如果它有用.
我收到一个错误:
OmniAuth::Strategies::Facebook::NoAuthorizationCodeError (must pass either a
`code` parameter or a signed request (via `signed_request` parameter or a
`fbsr_XXX` cookie)):
Run Code Online (Sandbox Code Playgroud)
它不是一直都会来的.它会偶尔出现,由airbrake通知.
谷歌搜索有很多链接,但无法找到合适的解决方案..任何人?omizersuth.rb在initializers目录下:
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], {:client_options => {:ssl => {:ca_path => "/etc/ssl/certs"}}, :scope => 'user_about_me,email,publish_actions,user_location,publish_stream,offline_access,user_interests,user_likes,user_hometown', :display => 'popup'}
OmniAuth.config.on_failure = Proc.new do |env|
#this will invoke the omniauth_failure action in SessionsController.
"SessionsController".constantize.action(:omniauth_failure).call(env)
end
end
Run Code Online (Sandbox Code Playgroud)
PS:我正在使用facebook javascript sdk和facebook-omniauth
我正在通过现有facebook帐户登录网站.所以我注册了一个Facebook应用程序和存储的API,并秘密在development.rb和production.rb文件.然后我用omniauth-facebook gem+ devise gem来实现这个.它完美无缺.
顺便说一下,用户可以通过内部认证(通过设计)或通过usig facebook帐户登录.
但是有一个奇怪的问题.只有在我注册了一个应用程序登录facebook帐户时,它才能完美运行.
所以我注册了另一个没有在我的Rails应用程序中使用的应用程序并尝试登录的Facebook帐户.它导致错误"发生错误.请稍后再试." ... "无法通过Facebook帐户验证您,因为"Csrf检测到""
我试图使用1.4.0 omniauth-facebook gem而不是1.4.1但它也导致错误" must pass either acode parameter or a signed request (viasigned_request parameter or afbsr_XXX cookie)"
宝石
oauth2 (0.8.0)
omniauth (1.1.0)
omniauth-oauth2 (1.1.0)
omniauth-facebook (1.4.1)
warden (1.2.1)
devise (2.1.2)
Run Code Online (Sandbox Code Playgroud)
你的想法?
如果我登录到facebook.com,我希望调用FB.getLoginStatus将返回status ='not_authorized'.相反,它返回status ='unknown',即使我为'force'参数传递true也是如此.
如果我调用FB.login,然后调用FB.getLoginStatus,我得到status ='connected'.说得通.
如果我调用FB.login,重新加载页面,然后调用FB.getLoginStatus,我得到status ='unknown'.没有意义.如果我添加'true'作为第二个参数(即力),我仍然得到status ='unknown'.(在这种情况下,我希望status ='not_authorized'.)
似乎没有办法在实践中获得status ='not_authorized'.
难道我做错了什么?这是FB.getLoginStatus或其文档中的错误吗?
这是一个最小的测试页面:http: //pastebin.com/NqiBXni2
语境:
我正在编写一个网站小部件,显示公共Facebook页面的帖子.(这可以在不通过app访问令牌提示用户的情况下访问.)每个帖子都有一个"赞"/"不同"链接.为了确定是否显示"喜欢"或"不喜欢",我需要知道浏览用户的Facebook ID是什么,以便我可以检查它是否在帖子的喜欢列表中.