AccessToken.getScreenName() reutns null in twitter integration android
integrate twitter with my android app i successfully get the token and tokeSecreat but when i fetch the screen name of twitter it gives me null how to solve this.below is the AccessToken i get from the twitter
AccessToken a = new AccessToken(
httpOauthConsumer.getToken(),
httpOauthConsumer.getTokenSecret());
System.out.println("Urgntly"+a.getScreenName());
a.getScreenName() gives me null.how to get the ScreenN开发者_Go百科ame of Twitter userName.
I dont know whether you are using any API for Twitter or not. But i have used Twitter4j and done this way
AccessToken a = new AccessToken(token, secret);
final Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(Constants.CONSUMER_KEY,
Constants.CONSUMER_SECRET);
twitter.setOAuthAccessToken(a);
and then using that twitter object
try {
twitter.getScreenName();
} catch (IllegalStateException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (TwitterException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
Use like this:
AccessToken a = new AccessToken(token,secret);
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);
twitter.setOAuthAccessToken(a);
//Some information is available through method calls
int myid=twitter.getId();
String username=twitter.getScreenName();
username will return here://
精彩评论