在 android 中从 Facebook 注销的代码
Code for logout from Facebook in android
我正在使用自定义 Facebook 登录按钮。这是我的代码。我正在使用会话管理器来存储整个 app.I 的电子邮件和名称已在第三个 activity 中使用注销按钮。
如何退出 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());
}
});
}
任何人都可以帮助我。请
您可以使用 Facebook Graph API
从 Facebook
注销。
LoginManager.getInstance().logOut();
希望对您有所帮助!
您需要使用:
LoginManager.getInstance().logOut();
首先,您需要Initialize SDK
:
FacebookSdk.sdkInitialize(getApplicationContext());
然后
LoginManager.getInstance().logOut();
我正在使用自定义 Facebook 登录按钮。这是我的代码。我正在使用会话管理器来存储整个 app.I 的电子邮件和名称已在第三个 activity 中使用注销按钮。
如何退出 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());
}
});
}
任何人都可以帮助我。请
您可以使用 Facebook Graph API
从 Facebook
注销。
LoginManager.getInstance().logOut();
希望对您有所帮助!
您需要使用:
LoginManager.getInstance().logOut();
首先,您需要Initialize SDK
:
FacebookSdk.sdkInitialize(getApplicationContext());
然后
LoginManager.getInstance().logOut();