Search code examples
androidresttwittertwitterkitapiclient

Twitter Kit Android - TwitterApiClient retweet does not work


In my app so far, I am displaying a tweet (my own for now) using the Twitter Kit for Android and have a Retweet button with which I am attempting to (go figure) retweet using the Twitter API Client.

Here are the links I referred to before this:

1) Twitter REST APIs from Android

2) Twitter Community Discussion on Retweeting using the TwitterApiClient

This is the code I'm using:

    val twApiClient: TwitterApiClient = TwitterCore.getInstance().apiClient
    tbTweet.setOnMenuItemClickListener {
        when (it.itemId) {
            R.id.item_retweet -> {
                val call: Call<Tweet> = twApiClient.statusesService.retweet(tweetID, true)
                Log.i("Retweet", if (call.isExecuted) "Successful" else "Failed")
            }
        }
        true
    }

I'm not getting any errors but when I go to my Profile Page on twitter, the retweet doesn't show up. The same problem has been stated in the 2nd link I provided, but no solution was given.

I also Log out the Execution Status. It comes as "Failed", so I know that the call retweet() isn't even executing. But why?

What is the problem and how do I fix it?


Solution

  • So, apparently the code above is incomplete. You have to call execute() on the call object that is returned from the retweet(tweetId, true) method. And then, you can call an onCompleteListener to see if your retweet was successful or not.