使用Twitter的android sdk登录后,如何获得用户的姓名和电子邮件?
TwitterAuthClient authClient = new TwitterAuthClient();
authClient.requestEmail(session, new Callback() {
@Override
public void success(Result result) {
Toast.makeText(getApplicationContext(),"Users email : "+result.data.toString,Toast.LENGTH_LONG).show();
}
@Override
public void failure(TwitterException exception) {
// Do something on failure
}
});
答案 0 :(得分:4)
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(consumerKey);
builder.setOAuthConsumerSecret(SecretKet);
User user;
AccessToken newAcc = new AccessToken(getoken, getokensecret);
Twitter twitter = new TwitterFactory(builder.build())
.getInstance(newAcc);
try {
String mUserName = twitter.getAccountSettings().getScreenName();
user = twitter.showUser(mUserName);
String username = user.getName();
String email= user.getEmail();
String oauth_uid = Integer.toString((int) user.getId());
} catch (TwitterException e) {
Log.v("ERROR", "API_Get_Twitter_Registration_DATA"+e.toString())
e.printStackTrace();
}