Android Facebook 整合问题 (fb sdk 4)
Android Facebook integration issue (fb sdk 4)
我在我的应用程序中实现了 facebook 登录。因此,该代码在第一次从 facebook 检索用户详细信息时运行,但是当我第二次使用 fb 登录时,将执行 oncancel 部分,如果我再次清除应用程序数据并再次使用 fb 登录,它会再次运行。
这是我在 facebook 上注册应用程序的代码。
protected void Registerwithfb()
{
// TODO Auto-generated method stub
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile,user_about_me, email, user_birthday, user_friends"));
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult result) {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
if (AccessToken.getCurrentAccessToken() != null) {
GraphRequest request = GraphRequest.newMeRequest(result.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
// TODO Auto-generated method stub
JSONObject json = response.getJSONObject();
try {
if (json != null) {
String name = json.getString("name");
String id = json.getString("id");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "name,email,first_name,last_name");
// Toast.makeText(getApplicationContext(), parameters.toString(), Toast.LENGTH_LONG).show();
request.setParameters(parameters);
request.executeAsync();
}
}
@Override
public void onCancel() {
// TODO Auto-generated method stub
System.out.println("cancelled");
}
@Override
public void onError(FacebookException error) {
// TODO Auto-generated method stub
System.out.println(error);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//super.onActivityResult(requestCode, resultCode, data);
// facebook.authorizeCallback(requestCode, resultCode, data);
//callbackManager.onActivityResult(requestCode, resultCode,data);
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
protected void Registerwithfb()
{
// TODO Auto-generated method stub
callbackManager = CallbackManager.Factory.create();
//I simply added this line
LoginManager.getInstance().logOut();
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile,user_about_me, email, user_birthday, user_friends"));
我在我的应用程序中实现了 facebook 登录。因此,该代码在第一次从 facebook 检索用户详细信息时运行,但是当我第二次使用 fb 登录时,将执行 oncancel 部分,如果我再次清除应用程序数据并再次使用 fb 登录,它会再次运行。
这是我在 facebook 上注册应用程序的代码。
protected void Registerwithfb()
{
// TODO Auto-generated method stub
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile,user_about_me, email, user_birthday, user_friends"));
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult result) {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
if (AccessToken.getCurrentAccessToken() != null) {
GraphRequest request = GraphRequest.newMeRequest(result.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
// TODO Auto-generated method stub
JSONObject json = response.getJSONObject();
try {
if (json != null) {
String name = json.getString("name");
String id = json.getString("id");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "name,email,first_name,last_name");
// Toast.makeText(getApplicationContext(), parameters.toString(), Toast.LENGTH_LONG).show();
request.setParameters(parameters);
request.executeAsync();
}
}
@Override
public void onCancel() {
// TODO Auto-generated method stub
System.out.println("cancelled");
}
@Override
public void onError(FacebookException error) {
// TODO Auto-generated method stub
System.out.println(error);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//super.onActivityResult(requestCode, resultCode, data);
// facebook.authorizeCallback(requestCode, resultCode, data);
//callbackManager.onActivityResult(requestCode, resultCode,data);
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
protected void Registerwithfb()
{
// TODO Auto-generated method stub
callbackManager = CallbackManager.Factory.create();
//I simply added this line
LoginManager.getInstance().logOut();
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile,user_about_me, email, user_birthday, user_friends"));