简体   繁体   中英

Android Twitter4J - Authentication credentials are missing

I'm not sure what I've got wrong. I have a twitter4j.properties file made, I've tried a constructor, no luck. I keep getting this error.

I'm using twitter4j-core-android-2.2.5.jar

java.lang.IllegalStateException: Authentication credentials are missing. See http://twitter4j.org/configuration.html for the detail.

String twitterpost = "testing";

Twitter twitter = new TwitterFactory().getInstance();
Status status = twitter.updateStatus(twitterpost);
System.out.println("Successfully updated the status to [" + status.getText() + "].");

The twitter4j.properties is in the root of the project, I also tried moving it around with no luck.

Thanks for any help.

请添加任何有效的回调URL,然后它将对我有用。并且还请检查您的访问权限。

Not sure this way it will work, consider using xAuth or try oAuth trick as bellow

     //Use xAuth over OAuth , with xAuth you can pass id and pwd to get instance 
     public static Twitter xAuth(String uname, String pwd, Context ctx)
                    throws TwitterException {
            Twitter twitter = new TwitterFactory().getInstance(uname, pwd);
            AccessToken accessToken = twitter.getOAuthAccessToken();
            save(accessToken, ctx);
            return getTwitterInstace(accessToken);
    }

   // or try this with oAuth
    System.setProperty("twitter4j.oauth.consumerKey",
            TWITTER_CONSUMER_KEY);
            System.setProperty("twitter4j.oauth.consumerSecret",
            TWITTER_CONSUMER_SECRET); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM