How To Get Email From Facebook Sdk 4.0
I'm working on android Login with Facebook After login i want to save the data from Facebook i want to save the following data from Facebook First Name Middle Name Last Name User
Solution 1:
Try This It's Work For me
login.registerCallback(callbackManager, newFacebookCallback<LoginResult>() {
@OverridepublicvoidonSuccess(LoginResult loginResult) {
if (AccessToken.getCurrentAccessToken() != null) {
RequestData();
}
}
@OverridepublicvoidonCancel() {
}
@OverridepublicvoidonError(FacebookException exception) {
}
});
privatevoidRequestData() {
GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), newGraphRequest.GraphJSONObjectCallback() {
@OverridepublicvoidonCompleted(JSONObject object,GraphResponse response) {
final JSONObject json = response.getJSONObject();
try {
if(json != null){
text = "<b>Name :</b> "+json.getString("name")+"<br><br><b>Email :</b> "+json.getString("email")+"<br><br><b>Profile link :</b> "+json.getString("link");
/*details_txt.setText(Html.fromHtml(text));
profile.setProfileId(json.getString("id"));*/Log.e(TAG, json.getString("name"));
Log.e(TAG, json.getString("email"));
Log.e(TAG, json.getString("id"));
//web.loadData(text, "text/html", "UTF-8");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle parameters = newBundle();
parameters.putString("fields", "id,name,link,email,picture");
request.setParameters(parameters);
request.executeAsync();
}
//Get Profile Picture from id
publicstaticBitmapgetFacebookProfilePicture(String userID){
try {
URL imageURL = newURL("https://graph.facebook.com/" + userID + "/picture?type=large");
Log.e(TAG,imageURL.toString());
try {
bitmap = BitmapFactory.decodeStream(imageURL.openConnection().getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
return bitmap;
}
Post a Comment for "How To Get Email From Facebook Sdk 4.0"