Android Twitter xAuth example using twitter4j

六眼飞鱼酱① 提交于 2019-11-28 06:38:49
success_anil

I ' ve used following


ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

     configurationBuilder.setOAuthConsumerKey(Consumer__Key);
     configurationBuilder.setOAuthConsumerSecret(Consumer_Secret);
     Configuration configuration = configurationBuilder.build();

     Twitter twitter = new TwitterFactory(configuration).getInstance("username","password"); 

     AccessToken token = twitter.getOAuthAccessToken();
     System.out.println("Access Token " +token );

     String name = token.getScreenName();
     System.out.println("Screen Name" +name);

     PrintWriter out= response.getWriter();
     System.out.println(token);

And successfully login to Twitter using Android app using xauth

Version 2.2.2 of twitter4j as a slight change. This works:

Configuration configuration = new ConfigurationBuilder()
.setOAuthConsumerKey("your_customer_key")
.setOAuthConsumerSecret("your_customer_secret")
.build();

Twitter twitter = new TwitterFactory(configuration).getInstance(new BasicAuthorization(username, password)); // yes, use "BasicAuthorization" although that seems strange

AccessToken token = twitter.getOAuthAccessToken();
Log.d(TAG, "Access token: " + token.getToken());
Log.d(TAG, "Access token secret: " + token.getTokenSecret());

Remember that your twitter client application needs to be authorized to use xAuth before this works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!