问题
i'm new on android - facebook integration.
I'm trying to integrate my app with facebook, so i follow all the steps on the facebook tutorial, and things work fine (at least i'm abble to perform the login).
But when i try to use this following code, i realize that i can't import the library from the Facebook:
Session session = Session.getActiveSession();
I'm using Android Studio, and the IDE only give me the option to import the android.service.textservice.SpellCheckerService, but i guess that the right import is com.facebook.Session
Any ideas of what i'm missing here?
PS: FB SDK version is facebook-android-sdk-4.5.1
回答1:
Facebook remove session in new SDK. check my answer for same question
there full integration code is given by me.
you can check whether user is logged in or not by this code.
profile = Profile.getCurrentProfile().getCurrentProfile();
if (profile != null) {
// user has logged in
} else {
// user has not logged in
}
回答2:
After looking around, i realize that the Session class on the new facebook SDK is not used. Instead that i found something like this, it solved my question:
loginButton = (LoginButton)findViewById(R.id.login_button);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.e("Content", "User ID: " + loginResult.getAccessToken().getUserId() + "\n" + "Auth Token: " + loginResult.getAccessToken().getToken());
}
@Override
public void onCancel() {
//"If login attempt canceled.";
}
@Override
public void onError(FacebookException e) {
//"If login attempt Failed.";
}});
来源:https://stackoverflow.com/questions/32232606/android-facebook-integration-impossible-to-import-com-facebook-session