2016-11-28 55 views
0

我的应用程序有Facebook登录,使我们能够捕获用户的电子邮件地址和名称。但是,当具有阿拉伯文名称的用户正在登录时,Firstname显示为???????并且电子邮件也显示为????????。我不明白在哪里?来自。当用户有阿拉伯文名称时Facebook登录提供问题

我的Facebook登录代码如下。

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(); 
    } 

的功能,其中的个人资料信息被认为是:

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(); 
    } 

有没有办法阅读阿拉伯字符该功能可以修改?

回答

1

我不认为带有阿拉伯文字母的名字会通过Facebook登录来读取。您将不得不使用单独的登录名来捕获可能含有阿拉伯字母的字符串。