我的应用已登录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();
}
是否可以修改此功能以读取阿拉伯字符?
答案 0 :(得分:1)
我不认为带有阿拉伯字母的姓名会通过Facebook登录来阅读。你必须使用单独的登录信息来捕获可能包含阿拉伯字母的字符串。