androidfacebookfacebook-graph-apifacebook-login

Facebook login giving issues when users have Arabic name


My app has facebook login to enable us to capture users email address and name. However,when a user who has used non English alphabets in their name is logging in, the Firstname appears as ??????? and email also appears as ????????. I am not understanding where the ? is coming from.

My code for the facebook login is below.

 callbackManager = CallbackManager.Factory.create();
        LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);

        loginButton.setReadPermissions("email","public_profile");

        LoginManager.getInstance().registerCallback(callbackManager,
                new FacebookCallback<LoginResult>() {
                    private ProfileTracker mProfileTracker;

                    @Override
                    public void onSuccess(final LoginResult loginResult) {
                        // App code
                        /*
                        String st= loginResult.getAccessToken().getApplicationId();
                        setFacebookData(loginResult);
                        System.out.println(st);
                        */


                        if(Profile.getCurrentProfile() == null) {
                            mProfileTracker = new ProfileTracker() {
                                @Override
                                protected void onCurrentProfileChanged(Profile profile, Profile profile2) {
                                    // profile2 is the new profile
                                    Log.v("facebook - profile2", profile2.getFirstName());
                                   //

                                    mProfileTracker.stopTracking();
                                    profile.setCurrentProfile(profile2);
                                    setFacebookData(loginResult,profile2);
                                }
                            };
                            // no need to call startTracking() on mProfileTracker
                            // because it is called by its constructor, internally.
                        }
                        else {
                            Profile profile = Profile.getCurrentProfile();
                            Log.v("facebook - profile1", profile.getFirstName());
                            setFacebookData(loginResult,profile);
                        }



                    }

                    @Override
                    public void onCancel() {
                        // App code
                        Toast toast=Toast.makeText(context, "Aww!! The connection to Facebook seems to have broken.Please restart Docuwind!!", Toast.LENGTH_SHORT);
                        TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
                        v.setTextColor(Color.RED);
                        toast.show();
                        Intent intent = new Intent(context, RegisterActivity.class);
                        startActivity(intent);
                        finish();
                    }

                    @Override
                    public void onError(FacebookException exception) {
                        // App code
                        Toast toast=Toast.makeText(context, "Aww!! The connection to Facebook seems to have broken.Please try again!!", Toast.LENGTH_SHORT);
                        TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
                        v.setTextColor(Color.RED);
                        toast.show();
                        Intent intent = new Intent(context, RegisterActivity.class);
                        startActivity(intent);
                        finish();

                    }
                });

    }

    public void disconnectFromFacebook() {

        if (AccessToken.getCurrentAccessToken() == null) {
            return; // already logged out
        }

        new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions/", null, HttpMethod.DELETE, new GraphRequest
                .Callback() {
            @Override
            public void onCompleted(GraphResponse graphResponse) {

                LoginManager.getInstance().logOut();

            }
        }).executeAsync();
    }

The function where the profile information is taken is:

private void setFacebookData(final LoginResult loginResult,final Profile mprofile)
    {
        GraphRequest request = GraphRequest.newMeRequest(
                loginResult.getAccessToken(),
                new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(JSONObject object, GraphResponse response) {
                        // Application code
                        try {
                            Log.i("Response",response.toString());

                            String emailadd=null;

                           final String firstName = response.getJSONObject().getString("first_name");
                           final String lastName = response.getJSONObject().getString("last_name");
                            String gender = response.getJSONObject().getString("gender");

                            try {
                                emailadd = response.getJSONObject().getString("email");
                            }
                            catch(Exception e){
                                int n1= 1 + (int)(Math.random() * ((100 - 1) + 1));
                                emailadd=firstName.toLowerCase()+lastName.toLowerCase()+String.valueOf(n1);
                            }
                            final String email=emailadd;

                            savenameinsharedpref(firstName);
                            saveemailinsharedpref(email);
                            final String refreshedToken = FirebaseInstanceId.getInstance().getToken();
                          //  Profile profile = Profile.getCurrentProfile();

                          //  String link = profile.getLinkUri().toString();
                           // Log.i("Link",link);

                                Log.i("Login", "ProfilePic" + mprofile.getProfilePictureUri(200, 200));
                                Uri imageUri = mprofile.getProfilePictureUri(200, 200);

                                ImageView targetImageView = (ImageView) findViewById(R.id.imgview);


                                Glide
                                        .with(context)
                                        .load(imageUri)
                                        .into(targetImageView);

                                int myWidth = 512;
                                int myHeight = 384;

                                Glide.with(context)
                                .load(imageUri)
                                    .asBitmap()
                                    .into(new SimpleTarget<Bitmap>(myWidth, myHeight) {
                                        @Override
                                        public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
                                            // Do something with bitmap here.
                                            ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
                                            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos1);

                                           

                                          saveinsharedpref(bitmap);


                                        }
                                    });




                            Log.i("Login" + "Email", email);
                            Log.i("Login"+ "FirstName", firstName);
                            Log.i("Login" + "LastName", lastName);
                            Log.i("Login" + "Gender", gender);


                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
        Bundle parameters = new Bundle();
        parameters.putString("fields", "id,email,first_name,last_name,gender");
        request.setParameters(parameters);
        request.executeAsync();
    }

Is there any way this function could be modified to read non-English characters?


Solution

  • I do not think names with non English letters would be read through Facebook login.you will have to use a separate login for that which captures string which could have non English letters also.