I'm trying to implement Twitter's Retweet API to retweet a specific tweet. But I'm having AuthFailureError
while requesting that API. I'm unable to solve this issue and stuck for many days. Any help would be appreciated.
Code:
private fun retweetTweet(tweetId: String) {
val progressDialog = ProgressDialog(this)
progressDialog.setTitle("Please wait")
progressDialog.show()
val jsonObject = JSONObject()
jsonObject.put("tweet_id", "$tweetId")
val url = "https://api.twitter.com/2/users/$userId/retweets"
Log.d(TAG, "retweetTweet: url: $url")
Log.d(TAG, "retweetTweet: tweet_id: $tweetId")
Log.d(TAG, "retweetTweet: userId: $userId")
val jsonObjReq: JsonObjectRequest =
object : JsonObjectRequest(Method.POST, url, jsonObject, Response.Listener { response ->
progressDialog.dismiss()
Log.d(TAG, "retweetTweet: $response")
try {
Log.d(TAG, "retweetTweet: ")
} catch (e: Exception) {
Log.e(TAG, "retweetTweet: ", e)
}
}, Response.ErrorListener { error ->
progressDialog.dismiss()
Log.e(TAG, "retweetTweet: ", error)
}) {
override fun getHeaders(): MutableMap<String, String> {
val headers: MutableMap<String, String> = HashMap()
val auth = "${Constants.TWITTER_BARRIER_TOKEN_KEY}"
headers["Authorization"] = auth
return headers
}
}
jsonObjReq.retryPolicy = DefaultRetryPolicy(5000, 3, 1.0f)
Volley.newRequestQueue(this).add(jsonObjReq)
}