Android开Facebook的电子邮件地址
问题描述:
我做了Facebook登录,但我不知道如何获得电子邮件地址,并以另一种形式Android开Facebook的电子邮件地址
所以显示出来,这是代码
private void nextActivity(Profile profile){
if(profile != null){
Intent main = new Intent(LogInTo.this, SetUsername.class);
main.putExtra("name", profile.getFirstName());
main.putExtra("surname", profile.getLastName());
//main.putExtra("email", profile.get());
main.putExtra("imageUrl",
profile.getProfilePictureUri(200,200).toString());
startActivity(main);
finish();
}
}
这是我的回调
LoginButton loginButton = (LoginButton)findViewById(R.id.loginButton);
FacebookCallback<LoginResult> callback = new
FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Profile profile = Profile.getCurrentProfile();
nextActivity(profile);
Toast.makeText(getApplicationContext(), "Logging in...", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException e) {
}
};
loginButton.setReadPermissions(Arrays.asList("user_friends"));
loginButton.registerCallback(callbackManager, callback);
而且这是你从Facebook获得的电子邮件地址显示在另一种形式的代码
Bundle inbundle = getIntent().getExtras();
String name = inbundle.get("name").toString();
String surname = inbundle.get("surname").toString();
FbFullname = (EditText) findViewById(R.id.fbfullname);
FbFullname.setText("" + name + " " + surname);
FbUsername = (EditText) findViewById(R.id.fbusername);
FbType = (EditText) findViewById(R.id.fbtype);
FbEmail = (EditText) findViewById(R.id.fbemail);
答
loginButton.setReadPermissions("public_profile email");`
在创建loginButton之后添加此行。
,并为获得详细
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) {
JSONObject data = json.getJSONObject("picture").getJSONObject("data");
String name=json.getString("name");
String email= json.getString("email");
String picUrl=data.getString("url");
}
} catch (JSONException e) {
}
}
});
+0
我已经添加这个,但如何获得它并以另一种形式显示它? –
+0
我已更新我的答案。在'onSuccess()'中加入。 –
+0
增加了,但是如何在textview中显示电子邮件。 –
你没有问用户权限读取他们的电子邮件。 – CBroe
我应该在这里添加吗? loginButton.setReadPermissions(Arrays.asList(“user_friends”)); –
Sharmaine Shane Amansec Cinens你已经收到邮件了吗?我也有这个问题 –