Detect if facebook user is logged in with no popups

前端 未结 1 1135
囚心锁ツ
囚心锁ツ 2021-01-22 00:37

I am trying to check if the user is logged in in facebook (and redirect to other page) but I can\'t open any popup for this:

This will work: but would open a popup in ca

相关标签:
1条回答
  • 2021-01-22 01:07

    You can use FB.getLoginStatus to get the info you want.

    The first time in the current browser session that FB.getLoginStatus is called, or the JS SDK is init'd with status: true, the response object will be cached by the SDK. Subsequent calls to FB.getLoginStatus will return data from this cached response.

    Example from documentation:

    FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
        // the user is logged in and has authenticated your
        // app, and response.authResponse supplies
        // the user's ID, a valid access token, a signed
        // request, and the time the access token 
        // and signed request each expire
        var uid = response.authResponse.userID;
        var accessToken = response.authResponse.accessToken;
      } else if (response.status === 'not_authorized') {
        // the user is logged in to Facebook, 
        // but has not authenticated your app
      } else {
        // the user isn't logged in to Facebook.
      }
    });
    
    0 讨论(0)
提交回复
热议问题