gpt4 book ai didi

java - Android 获取 facebook 电子邮件地址

转载 作者:行者123 更新时间:2023-12-02 13:22:51 28 4
gpt4 key购买 nike

我已经完成 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");` 

在创建登录按钮后添加此行。

以及获取详细信息

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) {

}
}
});

关于java - Android 获取 facebook 电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43511897/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com