gpt4 book ai didi

android - 如何从另一个 Activity 中注销 facebook?

转载 作者:太空宇宙 更新时间:2023-11-03 12:05:44 25 4
gpt4 key购买 nike

我使用的是 Facebook SDK 4.4.0。我想从另一个 Activity 中退出 Facebook?如何在另一个 Activity 中添加注销功能?我想在成功登录后转到另一个 Activity ,并在该 Activity 中添加注销功能

loginButton.registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
new fblogin().execute(loginResult.getAccessToken());

}

@Override
public void onCancel() {

}

@Override
public void onError(FacebookException e) {

}
});

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}

class fblogin extends AsyncTask<AccessToken, String, String> {

@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Wait.....");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}

protected String doInBackground(AccessToken... params) {
GraphRequest request = GraphRequest.newMeRequest(params[0],
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object,
GraphResponse response) {

Log.v("MainActivity", response.toString());

try {

username = object.getString("first_name");
emailid = object.getString("email");
gender = object.getString("gender");

Log.v("User Name", username);
Log.v("Email", emailid);
Log.v("Gender", gender);

} catch (JSONException e) {
// TODO Auto-generated catch
// block
e.printStackTrace();
}
}

});
Bundle parameters = new Bundle();
parameters.putString("fields",
"id,first_name,email,gender,birthday");
request.setParameters(parameters);
request.executeAndWait();

return null;
}

protected void onPostExecute(String file_url) {

pDialog.dismiss();

}

}

最佳答案

首先在您的 Activity 中初始化 FacebookSdk.sdkInitialize(getApplicationContext()); 然后在按钮点击事件中编写以下代码:

LoginManager.getInstance().logOut();

完成了!!!

关于android - 如何从另一个 Activity 中注销 facebook?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31758824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com