我正在使用自定义Facebook登录按钮。这是我的代码。我使用会话管理器存储整个app的电子邮件和名称。我在第三个活动中使用了注销按钮。
如何从Facebook退出
public void FB_Login(View view){
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "email"));
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// AccessToken.getCurrentAccessToken().getPermissions();
// Profile profile = Profile.getCurrentProfile();
// String firstName = profile.getFirstName();
// System.out.println(profile.getProfilePictureUri(20,20));
// System.out.println(profile.getLinkUri());
// App code
AccessToken.getCurrentAccessToken().getPermissions();
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
try {
email = object.getString("email");
name=object.getString("name");
// Creating user login session
// For testing i am stroing name, email as follow
// Use user real data
session.createLoginSession(name, email);
// Staring MainActivity
if (session.isLoggedIn()) {
in = new Intent(HomePageActivity.this, HomeSearchActivity.class);
in.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// Add new Flag to start new Activity
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(in);
finish();
}
} catch (JSONException e) {
e.printStackTrace();
}
Log.v("LoginActivity", response.toString());
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender, birthday");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
// App code
Log.v("LoginActivity", "cancel");
}
@Override
public void onError(FacebookException exception) {
// App code
Log.v("LoginActivity", exception.getCause().toString());
}
});
}
任何人都会帮助我。请。
答案 0 :(得分:4)
您可以使用Facebook
从Facebook Graph API
退出。
LoginManager.getInstance().logOut();
我希望它有所帮助!
答案 1 :(得分:2)
您需要使用:
LoginManager.getInstance().logOut();
答案 2 :(得分:2)
首先,您需要 Initialize SDK
:
FacebookSdk.sdkInitialize(getApplicationContext());
然后
LoginManager.getInstance().logOut();