Twitter4j use getOAuthAccessToken


#1

Hello I found twitter4j.org v2.2.6, and was trying to do the method you login the cession of twitter but I’m not getting.

My simplified code:

public class TwitterLab {
private static Twitter twitter;

public static void main(String[] args) {
String usr = “teste”;
String pass = “test”;

 try {
     twitter = new TwitterFactory().getInstance();
         AccessToken at = twitter.getOAuthAccessToken(usr, pass);

         twitter = new TwitterFactory().getInstance(at);
     User user = twitter.verifyCredentials();
     System.out.println("Successfully verified credentials of " + user.getScreenName());
     System.exit(0);
 } catch (TwitterException te) {
     te.printStackTrace();
     System.out.println("Failed to verify credentials: " + te.getMessage());
     System.exit(-1);
 }

}
}

Anyone can help me with some code, or explaining why it gives me the error:
java.lang.IllegalStateException: OAuth consumer key/secret combination not supplied


#2

I tried posting message to twitter , hope the following details might help :
Login to https://dev.twitter.com/ , create an application and get the consumerkey,consumersecretkey,accesstoken, accesstokensecretkey

Write the following lines in the source code

ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(“Your consumer key”)
.setOAuthConsumerSecret(“Your consumer secret key”)
.setOAuthAccessToken(“Access token”)
.setOAuthAccessTokenSecret(“Yout acccess token secret”);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();


#3

I also have a problem using twitter4j 2.2.6, similar code to above but on android system


#4

I’ve run the code using ConfigurationBuilder class, but always get the following error:

Permission denied: connect
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=b2b52c28 or
http://www.google.co.jp/search?q=1206f231
TwitterException{exceptionCode=[b2b52c28-1206f231 b2b52c28-1206f207], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.5}

Anybody could make some suggestions?


#5

Hi All, I went into the same problem. Did you guys solve the problems? any suggestions? thanks in advance!


#6

Hello everyone,

I have the same problem with the others. Is there any way to overcome this problem?


#7

Hello Team,
I am a developer using Twitter 1.1 API for automatic tweet but every time twitter is asking for login and authorize how i fixed it please please help me…
I want to tweet on twitter in background process same as justunfollow.com and tweetlonger do.
Thanks in advance.


#8

Hello Team ,

I am trying to use TWITTER 4j API . I have wriiten the below code :-

public final class TwitterConnection {

public static void main(String[] args) throws IOException {
 String testPost = "hello from otc";
 ConfigurationBuilder cb = new ConfigurationBuilder();
 cb.setDebugEnabled(true)
   .setOAuthConsumerKey("NGvsDAA0WUVudqQBpMgo5H7Zh")
   .setOAuthConsumerSecret("DrGPChCUeF6gEDFkkygnZSEC88l1pFYumV8LgCIELj1YkHG2VN")
   .setOAuthAccessToken("1725870422-d32GwizZYclX4KXE5vlbbvDSWJRpPnMZwcLR0MC")
   .setOAuthAccessTokenSecret("FFQgA9b1b8A0oEO9XbYBTDNUq0VbP5iuZO7gyJazAF93B");

try {
TwitterFactory factory = new TwitterFactory();
Twitter twitter = factory.getInstance();
AccessToken accestoken = new AccessToken(“1725870422-d32GwizZYclX4KXE5vlbbvDSWJRpPnMZwcLR0MC”, “FFQgA9b1b8A0oEO9XbYBTDNUq0VbP5iuZO7gyJazAF93B”);
twitter.setOAuthAccessToken(accestoken);
Status status = twitter.updateStatus(testPost);
System.out.println(“it worked!”);
if (status.getId() == 0) {
System.out .println(“Error occured while posting tweets to twitter”);
}
} catch (Exception e) {
e.printStackTrace();
}

Error :-

java.lang.IllegalStateException: OAuth consumer key/secret combination not supplied
at twitter4j.TwitterBaseImpl.getOAuth(TwitterBaseImpl.java:392)
at twitter4j.TwitterBaseImpl.setOAuthAccessToken(TwitterBaseImpl.java:378)
at com.accure.twitter.TwitterConnection.main(TwitterConnection.java:59)

Please help me for the above issue .

Thanks and Regards,
Trupti Pradhan

}

}