I am not able to get information from Twitter Api, not giving any information, I need user profile pic, email and users personal account info, I have tried almost every thin
1.
twitter_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
client.authorize(SignUpToConnectActivity.this, new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
String oauth_token_secret = result.data.getAuthToken().secret;
String oauth_token = result.data.getAuthToken().token;
TwitterSession user = result.data;
getUserDetails(user);
}
@Override
public void failure(TwitterException exception) {
//
}
});
}
})
2.
public void getUserDetails(TwitterSession twitterSession) {
Twitter.getApiClient(twitterSession).getAccountService().verifyCredentials(true, false).enqueue(new Callback<User>() {
@Override
public void success(Result<User> userResult) {
try {
User user = userResult.data;
String fullname = user.name;
String twitterID = user.getId();
String userSocialProfile = user.profileImageUrl;
String userEmail = user.email;
String userFirstNmae = fullname.substring(0, fullname.lastIndexOf(" "));
String userLastNmae = fullname.substring(fullname.lastIndexOf(" "));
String userScreenName = user.screenName;
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void failure(TwitterException e) {
}
});
}
Using this, you are able to get user information.
This works for me Twitter 3+ api calling change
twitterLoginButton.setCallback(new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
// Do something with result, which provides a TwitterSession for making API calls
TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient();
AccountService accountService = twitterApiClient.getAccountService();
Call<com.twitter.sdk.android.core.models.User> call = accountService.verifyCredentials(true, true, true);
call.enqueue(new Callback<com.twitter.sdk.android.core.models.User>() {
@Override
public void success(Result<com.twitter.sdk.android.core.models.User> result) {
//here we go User details
}
@Override
public void failure(TwitterException exception) {
}
});
}
@Override
public void failure(TwitterException exception) {
// Do something on failure
}
});