okhttp3 application/json get kotlin
val BASE_URL = "https://api.unsplash.com"
val ACCESS_KEY = "..."
val path = "/photos/$id"
val uri = Uri.parse(BASE_URL)
.buildUpon()
.appendEncodedPath(path)
//.appendPath(path)
.build()
val client = OkHttpClient()
val request = Request.Builder()
.url(uri.toString())
.addHeader("Accept-Version", "v1")
.addHeader("Authorization", "Client-ID $ACCESS_KEY")
.get()
.build()
val response = client.newCall(request).execute()
val jsonDataString = response.body()?.string()
val json = JSONObject(jsonDataString)
if (!response.isSuccessful) {
val errors = json.getJSONArray("errors").join(", ")
throw Exception(errors)
}
val rawUrl = json.getJSONObject("urls").getString("raw")
Also in JavaScript:
- display form input on console jquery
- how to make a javascript for loop
- how to flatten nested arrays javascript
- js find intersection point
- react manifest.json 404 (not found)
- access angular app outside localhost
- jquery var_dump array
- javascript element edit text
- get erquest jquery
- nodejs config file
- rest parameter javascript
- import img react in another file
- react can't import file 3 folders up
- what is code.jquery integrity crossorigin
- javascript submit a form
- mongoose setup
- how to get an array from another script in js
- remove in javascript
- angularjs class directive prepend
- Exception in thread "main" org.openqa.selenium.JavascriptException:
- javascript add input
- the original image of nodejs image
- jest Cross origin http://localhost forbidden
- remove extra space in string js