我正在使用Facebook Android SDK' com.facebook.android:facebook-android-sdk:4.13.1'版。
我对这个Facebook版本的问题与此Fiddle完全相同。单击Facebook登录按钮后,我需要重定向到我的主屏幕,而不返回登录屏幕。此SDK版本(4.13.1)可以解决/支持此功能吗?请帮帮我。
loginButton = (LoginButton) findViewById(R.id.fb_login_button);
loginButton.setReadPermissions("public_profile email");
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
if (AccessToken.getCurrentAccessToken() != null) {
RequestData();
}
}
@Override
public void onCancel() {
// code for cancellation
Toast.makeText(getBaseContext(), "Login Cancelled", Toast.LENGTH_SHORT).show();
Log.d("i am in ", "cancel method");
// Toast.makeText(getApplicationContext(),"Login as cancelled",Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException e) {
Log.d("i am in ", "error method");
Toast.makeText(getApplicationContext(), "Internet Error occurred Please try again latter", Toast.LENGTH_SHORT).show();
/* Log.v("LoginActivity", e.getCause().toString());*/
}
});
private void RequestData() {
graphRequest = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
String emailId;
String profilePicUrl;
@Override
public void onCompleted(JSONObject object,GraphResponse response) {
JSONObject json = response.getJSONObject();
if (response != null) {
try {
JSONObject data = response.getJSONObject();
username = json.getString("name");
emailId = json.getString("email");
}
catch (Exception e) {
e.printStackTrace();
}
}
CallingRetrofit(emailId,profilePicUrl);
LoginManager.getInstance().logOut();
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link,email,picture");
graphRequest.setParameters(parameters);
graphRequest.executeAsync();
}
在CallingRetrofit功能中,如果他是授权用户,我将意图传递给主屏幕。