我试图通过面料从Twitter获取电子邮件,任何人都可以帮助我如何获得它。我也试过没有面料,但它没有用。
我的代码如下所示。
twitterLoginButton.setCallback(new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
session = result.data;
String username = session.getUserName();
Long userid = session.getUserId();
Log.d(":: Name ::", session.getUserName());
getUserData();
}
@Override
public void failure(TwitterException exception) {
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
twitterLoginButton.onActivityResult(requestCode, resultCode, data);
}
void getUserData() {
Call<User> call = Twitter.getApiClient(session).getAccountService()
.verifyCredentials(true, false);
call.enqueue(new Callback<User>() {
@Override
public void success(Result<User> result) {
User user = result.data;
String twitterImage = user.profileImageUrl;
try {
Log.d("imageurl", user.profileImageUrl);
Log.d("name", user.name);
// Log.d("email", user.email);
Log.d("des", user.description);
Log.d("followers ", String.valueOf(user.followersCount));
Log.d("createdAt", user.createdAt);
Log.d("::Name ::", user.name);
session = Twitter.getSessionManager().getActiveSession();
TwitterAuthToken authToken = session.getAuthToken();
String token = authToken.token;
String secret = authToken.secret;
authClient = new TwitterAuthClient();
authClient.requestEmail(session, new Callback<String>() {
@Override
public void success(Result<String> result) {
// Do something with the result, which provides the email address
Log.d("::::result:::::", result.response + "");
}
@Override
public void failure(TwitterException exception) {
// Do something on failure
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void failure(TwitterException exception) {
}
});
}