Trying to post an update on my account but get 401 back

api

#1

Hello,

I have created an application and then generated Access Token. The app has read-write permission.

In Java I attempt a really simple call to post an status update like this:

 formBody = new FormBody.Builder()
          .add("status", encode("hello"))
          .build();
 
  String authString = "OAuth oauth_consumer_key=\"xxxxxx\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"1478866860\",oauth_nonce=\"e44f98b3b4bc404faff97be81467cda3\",oauth_version=\"1.0\",oauth_signature=\"xxxxxx\",oauth_token=\"{accessToken}\";

      request = new Request.Builder()
          .url("https://api.twitter.com/1.1/statuses/update.json")
          .method("POST", formBody)
          .addHeader("Authorization", authString)
          .build();

    response = new OkHttpClient().newCall(request).execute();

{"errors":[{"code":32,"message":"Could not authenticate you."}]}

Is there something I need to enable ?


#2

It is likely that you’re not signing the request correctly. I’d suggest taking a look at one of the pre-existing Twitter libraries like Twitter4J, which encapsulates all of the Oauth for you.