가 늦게 회신,하지만 지금 버전에서 Facebook SDK
의 4.25.0
는 방법이있다 :
public void retrieveLoginStatus(Context context,
LoginStatusCallback responseCallback)
상태 :
은
사용자의 로그인 상태를 검색합니다. 사용자가 Android 용 Facebook 앱에 동일한 기기에 로그인하고 그 사용자가 이전에 앱에 로그인 한 경우 앱에 대한 액세스가 토큰을 반환합니다. . 액세스 토큰이 다음 검색 한 경우 건배은 로그인 한 사용자를 말하는
을 을 표시됩니다 그리고처럼 사용할 수 있습니다 : 이것은 이미 here 대답
LoginManager.getInstance().retrieveLoginStatus(this, new LoginStatusCallback()
{
@Override
public void onCompleted(AccessToken accessToken)
{
GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback()
{
@Override
public void onCompleted(JSONObject object, GraphResponse response)
{
Log.e(TAG, object.toString());
Log.e(TAG, response.toString());
try
{
userId = object.getString("id");
profilePicture = new URL("https://graph.facebook.com/" + userId + "/picture?width=500&height=500");
Log.d("PROFILE_URL", "url: " + profilePicture.toString());
if (object.has("first_name"))
{
firstName = object.getString("first_name");
}
if (object.has("last_name"))
{
lastName = object.getString("last_name");
}
if (object.has("email"))
{
email = object.getString("email");
}
if (object.has("birthday"))
{
birthday = object.getString("birthday");
}
if (object.has("gender"))
{
gender = object.getString("gender");
}
Intent main = new Intent(LoginActivity.this, MainActivity.class);
main.putExtra("name", firstName);
main.putExtra("surname", lastName);
main.putExtra("imageUrl", profilePicture.toString());
startActivity(main);
finish();
}
catch (JSONException e)
{
e.printStackTrace();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
}
});
//Here we put the requested fields to be returned from the JSONObject
Bundle parameters = new Bundle();
parameters.putString("fields", "id, first_name, last_name, email, birthday, gender");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onFailure()
{
Toast.makeText(LoginActivity.this, "Could not log in.", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(Exception exception)
{
Toast.makeText(LoginActivity.this, "Could not log in.", Toast.LENGTH_SHORT).show();
}
});
.
로그 아웃은 클라이언트 측 이벤트이기 때문에 jsdk의 이벤트를 구독하는 것이 유일한 방법이라고 생각합니다. 나는 서버 측 대안이 있다고 생각하지 않는다. FB.Event.subscribe ('auth.sessionChange', function (response) –
고마워요 - 세션이 아직 남아 있기 전에 페이지를 새로 고침하고 초기화를 호출 한 후에 만 작동하는 것 같습니다 – Daniel