如何在文本视图中显示从 Facebook 提取的数据

How to display extracted data from Facebook in a textview

我编写了用于连接 Facebook 并提取用户名、电子邮件 ID 和个人资料 link 的代码。所有提取的详细信息在单击我想要的 button.But 时以不同的 activity 显示它在登录过程完成后立即在同一活动中显示它 successfully.which 意味着我需要在 onSuccess 之后编辑代码,但我不知道如何获取代码

public class MainActivity extends AppCompatActivity {
CallbackManager callbackManager;
Button share,details;
ShareDialog shareDialog;
LoginButton login;
ProfilePictureView profile;
Dialog details_dialog;
TextView details_txt;
TextView details_txtx;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_main);
    callbackManager = CallbackManager.Factory.create();

    login = (LoginButton)findViewById(R.id.login_button);
    profile = (ProfilePictureView)findViewById(R.id.picture);
    shareDialog = new ShareDialog(this);
    share = (Button)findViewById(R.id.share);

    details = (Button)findViewById(R.id.details);
    login.setReadPermissions("public_profile email");
    share.setVisibility(View.INVISIBLE);


    details.setVisibility(View.INVISIBLE);
    details_dialog = new Dialog(this);
    details_dialog.setContentView(R.layout.dialog_details);
    details_dialog.setTitle("Details");
    details_txtx = (TextView)details_txtx.findViewById(R.id.details_tetx);

    details.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            details_dialog.show();
        }
    });

    if(AccessToken.getCurrentAccessToken() != null){
        RequestData();
        share.setVisibility(View.VISIBLE);
        details.setVisibility(View.VISIBLE);
    }
    login.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(AccessToken.getCurrentAccessToken() != null) {
                share.setVisibility(View.INVISIBLE);
                details.setVisibility(View.INVISIBLE);
                profile.setProfileId(null);
            }
        }
    });
    share.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ShareLinkContent content = new ShareLinkContent.Builder().build();
            shareDialog.show(content);

        }
    });
    login.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult ) {


            if(AccessToken.getCurrentAccessToken() != null){
                RequestData();
                share.setVisibility(View.VISIBLE);
                details.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException exception) {
        }
    });

}
public void RequestData(){
    GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
        @Override
        public void onCompleted(JSONObject object,GraphResponse response) {

            JSONObject json = response.getJSONObject();
            try {
                if(json != null){
                    String text = "<b>Name :</b> "+json.getString("name")+"<br><br><b>Email :</b> "+json.getString("email")+"<br><br><b>Profile link :</b> "+json.getString("link");
                    details_txt.setText(Html.fromHtml(text));
                    profile.setProfileId(json.getString("id"));
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,link,email,picture");
    request.setParameters(parameters);
    request.executeAsync();
}

要清楚:我只想在成功登录后在同一 activity 中显示提取的详细信息,您能帮忙吗?

请检查以下代码

protected void connectToFacebook() {
    ArrayList<String> list = new ArrayList<String>();
    list.add("email");
    // LoginManager.getInstance().logInWithReadPermissions(this, list);
    LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email", "user_photos", "public_profile"));

    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            // App code
            GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject json, GraphResponse response) {
                    // Application code
                    if (response.getError() != null) {
                        System.out.println("ERROR");
                    } else {
                        System.out.println("Success");
                        String jsonresult = String.valueOf(json);
                        System.out.println("JSON Result" + jsonresult);

                        String fbUserId = json.optString("id");
                        String fbUserFirstName = json.optString("name");
                        String fbUserEmail = json.optString("email");
                        String fbUserProfilePics = "http://graph.facebook.com/" + fbUserId + "/picture?type=large";
                        callApiForCheckSocialLogin(fbUserId, fbUserFirstName, fbUserEmail, fbUserProfilePics, "fb");
                    }
                    Log.v("FaceBook Response :", 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);
            Utilities.showToast(mActivity, "" + exception);
        }
    });
}