开发者

AccessToken.getScreenName() reutns null in twitter integration android

开发者 https://www.devze.com 2023-04-13 03:15 出处:网络
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 th

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://

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号