0

Im trying to use Jsoup to make http Get request Discord Api, to get users information like this, what am I doing wrong ?

thread {

    val id = "MY_ID:"
    val token = "MY_TOKEN_BOT"

    val source = Jsoup.connect("https://discord.com/api/v9/users/${id}")
        .header("Authorization","Bot $token")
        .ignoreContentType(true)
        .method(Connection.Method.GET)
        .execute()
        .body()

    runOnUiThread {
        binding.txv.text = JSONObject(source).toString()
    }
}

Response code GET 403

org.jsoup.HttpStatusException: HTTP error fetching URL. Status=403, URL=[https://discord.com/api/v9/users/264097054047862794]
  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:890)
  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:829)
  at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:366)
  at com.example.jsouptester.MainActivity$testing$1.invoke(MainActivity.kt:80)
  at com.example.jsouptester.MainActivity$testing$1.invoke(MainActivity.kt:62)
  at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)
Elikill58
  • 4,050
  • 24
  • 23
  • 45
Darkryh
  • 31
  • 1
  • 4
  • But why use Jsoup for this? You're talking to an API (not fetching HTML web pages), so you could simply use a classic HTTP client and JSON serialization library. – Joffrey Jan 22 '22 at 20:00
  • actually y tryed used jsoup with another method of the discord API and it worked so i suposed, it can work with jsoup method. – Darkryh Jan 22 '22 at 20:21
  • but thanks for the advice i going to try with retrofit,to see if it works – Darkryh Jan 22 '22 at 20:30
  • oh men IT Worker with HttpURLConnection ty so much – Darkryh Jan 22 '22 at 20:57

0 Answers0