How can i get email address of a user via twitter API? I\'m using Twitter4j for Sign in with twitter
To Get Twitter Email and Profile Image URL , username, id you to call requestEmail method.
Also You to allow request email in your developer account of twitter. See below images.
Use Below code to Get user details.
btnTwitterLogin.setCallback(new Callback() {
@Override
public void success(Result result) {
TwitterSession session = TwitterCore.getInstance().getSessionManager().getActiveSession();
TwitterAuthToken authToken = session.getAuthToken();
TwitterAuthClient authClient = new TwitterAuthClient();
authClient.requestEmail(session, new Callback() {
@Override
public void success(Result result) {
String email =result.data;
String token = authToken.token;
String secret = authToken.secret;
String username = session.getUserName();
long userId = session.getUserId();
Log.e("neem", "success: \n Token => " + token + "\n Secret: " + secret + " \n Username: " + username + "\n Userid: " + userId+" \n Email: "+email);
}
@Override
public void failure(TwitterException exception) {
Log.e("neem", "failure: "+exception.getMessage() );
}
});
TwitterCore.getInstance().getApiClient(result.data).getAccountService().verifyCredentials(false,true,false).enqueue(new Callback() {
@Override
public void success(Result userResult) {
try {
String imageUrl = userResult.data.profileImageUrl;
String username = userResult.data.screenName;
Log.e("neem", "acount services: imageurl: "+imageUrl+"\n username: "+username );
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void failure(TwitterException e) {
}
});
}
@Override
public void failure(TwitterException exception) {
ShowToast(mcontext, "Login failed due to: \n "+exception.getMessage());
}
});