Check if a facebook user is connected to the application from server side in java

StackOverflow https://stackoverflow.com/questions/12015698

  •  27-06-2021
  •  | 
  •  

Вопрос

My application is written with JSF framework. There is a method in JavaScript API that allows to recognize if a user is connected to the application

FB.init({appId: "#{settings.fbClientId}", status: true, cookie: true});
FB.getLoginStatus(function(response) {
   if (response.status === 'connected') {
      var uid = response.authResponse.userID;
      var accessToken = response.authResponse.accessToken;
   }
}

I'm looking for a function that will allow me to do the same from the server-side. Currently I'm using restFB to make requests to the Facebook. It looks like this implementation has no support for authorization and related functionality. I know it is possible in PHP SDK and Python SDK, but cannot find anything like this in Java.

Note: I can do check with JS API and then make all necessary requests from server side, but it is not what I need. I'm looking for a solution that allows my doing everything from the server side.

Это было полезно?

Решение

Any server-side only technology is not capable of recognizing Facebook users re-visiting your app outside of Facebook (after a certain amount of time has passed anyway).

The reason is simple: Me logging in to Facebook creates cookies in my browser, that are set for the facebook.com domain. No server-side technique on my server (therefore, under my domain) is able to get the contents of these cookies.

The JS SDK however is able to make cross-domain requests to check if I am logged in to Facebook, and then set some cookies under my domain, by which any server-side technology can access my current status on next request.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top