0

im trying to post status updates to twitter. I am using the Twitter4j lib. My code runs without crashing but in the log cat is says "401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.

{"request":"\/1.1\/statuses\/update.json","error":"Read-only application cannot POST."}

any help? I have signed up on twitter and i check the read and write permissions.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Runnable runnable = new Runnable() {
        public void run() {
            ConfigurationBuilder builder = new ConfigurationBuilder();
            builder.setOAuthConsumerKey("kkwfh72794883jjg");
            builder.setOAuthConsumerSecret("77j3jgweqwewerrud3434567hgfd");



            // Access Token
            String access_token = "lokiujyhtgrfedvwn325zckjdhdgeAHGsw23";
            // Access Token Secret
            String access_token_secret = "QsRgfgHJMsjeh5762JHF2dgswrfMNQljsG";

            AccessToken accessToken = new AccessToken(access_token, access_token_secret);
            Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);

            // Update status
            try {
                twitter4j.Status response = twitter.updateStatus("updated via myapp");

                Log.d("Status", "> " + response.getText());

                // Error in updating status


                } catch (TwitterException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Log.d("Twitter Update Error", e.getMessage());
            }


        }
    };
    Thread mythread = new Thread(runnable);
    mythread.start();


}
Tim Zimmermann
  • 6,132
  • 3
  • 30
  • 36

2 Answers2

0

I was having similar issue. What I did was:

  1. Check if your app has Read and Write permissions
  2. If it doesn't, check the permissions radiobutton, and click Update Settings
  3. After that, you must manually regenerate your access tokens (I regenerated consumer key, too)

Hope this will help other strugglers.

Anhayt Ananun
  • 896
  • 1
  • 11
  • 27
0

I think you should change your code: Like this:

ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey("kkwfh72794883jjg");
builder.setOAuthConsumerSecret("77j3jgweqwewerrud3434567hgfd");
OAuthAuthorization auth = new OAuthAuthorization(builder.build());
// Access Token
String access_token = "lokiujyhtgrfedvwn325zckjdhdgeAHGsw23";
// Access Token Secret
String access_token_secret = "QsRgfgHJMsjeh5762JHF2dgswrfMNQljsG";
Twitter twitter = new TwitterFactory().getInstance(auth);
FelixSFD
  • 6,052
  • 10
  • 43
  • 117
Darshan Adakane
  • 87
  • 2
  • 14