Twitter update/status API is working on postman and not working in code Android

Viewed 50

I am integrating Twitter statuses/update.json API in Android Application. I am using retrofit for the API. This API is required OAuth 1.0 and I am generating all the required values and calling API it is giving me this response:

{"errors":[{"code":89,"message":"Invalid or expired token."}]}

When I pass all the required values in the Postman it is working.

Here is the way how I am passing values to Postman (form-urlencoded):

enter image description here

Following is the string which I generated in the code and passing in the header in Authorization

OAuth oauth_consumer_key="55pQiiN7hMwSEKMDqc0wYcH",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1617275741",oauth_nonce="675889204f9748a98a7f24c8c313d9bf",oauth_version="1.0",oauth_signature="vuH%2BpCkPNNEr9CnNzT6wXCj2k%3D",oauth_token="2997731-kzHvqPH2NeYnHOV6tFB1wtvXlk1qzUFk3pqUHA",oauth_token_secret="lDOo0Ozyjq2ngdGEr52IOPGxxbsXbWACxZEXLrvlcsO5p",oauth_consumer_secret="tqMmRHJ4kGbykxbOaYD1ZHJgfsKfFSCySpUOGpnIWWH6KjJ"

And it is giving me an error as mentioned above.

How I am generating signature:

private static String computeSignature(String baseString, String keyString) throws GeneralSecurityException, UnsupportedEncodingException {
        SecretKey secretKey = null;

        byte[] keyBytes = keyString.getBytes();
        secretKey = new SecretKeySpec(keyBytes, "HmacSHA1");

        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);

        byte[] text = baseString.getBytes();

        return new String(Base64.encodeBase64(mac.doFinal(text))).trim();
    } 

Am I missing anything? How can I resolve this error?

0 Answers
Related