Java 关于Facebook注销事件
当用户单击“注销”按钮时,是否有检查方法,我可以在我的android应用程序中登录:Java 关于Facebook注销事件,java,android,ios,facebook,sharedpreferences,Java,Android,Ios,Facebook,Sharedpreferences,当用户单击“注销”按钮时,是否有检查方法,我可以在我的android应用程序中登录: FacebookSdk.sdkInitialize(this.getApplicationContext()); callbackManager = CallbackManager.Factory.create(); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences
FacebookSdk.sdkInitialize(this.getApplicationContext());
callbackManager = CallbackManager.Factory.create();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
final SharedPreferences.Editor editor = sharedPreferences.edit();
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override public void onSuccess(LoginResult loginResult) {
// App code
Toast.makeText(getApplicationContext(), "Login successful" + loginResult.getAccessToken().toString(), Toast.LENGTH_LONG).show();
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
//textView.setText(response.toString());
JSONObject j_user = response.getJSONObject();
try {
KEY_ID = object.getString("id");
KEY_EMAIL = object.getString("email");
KEY_NAME = object.getString("name");
} catch (JSONException e) {
e.printStackTrace();
}
Log.i("stringazzo", response.toString());
Log.i("STRING", object.toString());
// Log.i("string", KEY_EMAIL);
// Log.i("string", KEY_ID);
// Log.i("string", KEY_NAME);
// Log.i("SHAREDPREFS",KEY_NAME);
// Log.i("SHAREDPREFS",KEY_EMAIL);
editor.putString("name", KEY_NAME);
editor.putString("email", KEY_EMAIL);
editor.putString("id", KEY_ID);
editor.commit();
System.out.println(editor.commit());
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
Toast.makeText(getApplicationContext(), "Login canceled", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException exception) {
Toast.makeText(getApplicationContext(), "Login error"+exception.getMessage().toString(), Toast.LENGTH_SHORT).show();
}
});
FacebookSdk.sdkinInitialize(this.getApplicationContext());
callbackManager=callbackManager.Factory.create();
SharedReferences SharedReferences=PreferenceManager.GetDefaultSharedReferences(此);
最终SharedReferences.Editor=SharedReferences.edit();
LoginManager.getInstance().registerCallback(callbackManager,
新建FacebookCallback(){
@成功时覆盖公共无效(LoginResult LoginResult){
//应用程序代码
Toast.makeText(getApplicationContext(),“登录成功”+loginResult.getAccessToken().toString(),Toast.LENGTH\u LONG.show();
GraphRequest请求=GraphRequest.newmereRequest(
loginResult.getAccessToken(),
新建GraphRequest.GraphJSONObjectCallback(){
@凌驾
公共空间未完成(
JSONObject对象,
GraphResponse(反应){
//应用程序代码
//setText(response.toString());
JSONObject j_user=response.getJSONObject();
试一试{
KEY_ID=object.getString(“ID”);
KEY_EMAIL=object.getString(“EMAIL”);
KEY_NAME=object.getString(“NAME”);
}捕获(JSONException e){
e、 printStackTrace();
}
Log.i(“stringazzo”,response.toString());
Log.i(“字符串”,object.toString());
//Log.i(“字符串”,关键字为电子邮件);
//Log.i(“字符串”,键号);
//Log.i(“字符串”,键名称);
//Log.i(“SHAREDPREFS”,密钥名称);
//Log.i(“SHAREDPREFS”,KEY_EMAIL);
编辑器.putString(“名称”,键名称);
编辑器.putString(“email”,KEY_email);
编辑器.putString(“id”,KEY_id);
commit();
System.out.println(editor.commit());
}
});
Bundle参数=新Bundle();
参数.putString(“字段”、“id、名称、电子邮件”);
请求。设置参数(参数);
request.executeAsync();
}
@凌驾
公开作废{
Toast.makeText(getApplicationContext(),“登录已取消”,Toast.LENGTH\u SHORT.show();
}
@凌驾
public void onError(facebook异常){
Toast.makeText(getApplicationContext(),“登录错误”+exception.getMessage().toString(),Toast.LENGTH_SHORT).show();
}
});
当用户登录我的应用程序时,我从Facebook获得一些数据,并将其保存在SharedReferences中,当用户登录时,登录按钮变为注销,我希望当用户单击注销按钮时,我的所有SharedReferences都将设置为“0”值
在我的iphone应用程序中也是如此
我该怎么做呢?facebook登录和注销按钮是相同的,单击时会触发相同的事件。因此,您要做的是,验证用户是否已登录 像这样:
Profile.fetchProfileForCurrentAccessToken(); //manually force profile fetching from current token
if(Profile.getCurrentProfile() != null) { //if it available
Log.d("TAG", "LOGGED ");
} else {
Log.d("TAG", "Profile is null UNLOGGED");
}
我希望有帮助