Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

StackExchange

Yuri Schimke edited this page Jul 18, 2018 · 6 revisions

Stack Exchange

API Documentation

Most APIs don't require authentication e.g. reading questions.

https://api.stackexchange.com/docs

Examples

$ okurl 'https://api.stackexchange.com/2.2/questions?order=desc&sort=activity&tagged=okhttp&site=stackoverflow&pagesize=3' | jq .items[].title
"Handling third party logins with okhttp's Authenticator interface"
"NodeMCU server bad response, when sending GET request from Android app"
"How to properly parse JSON Array in Android"

Authentication

Either use an existing granted token, or visit stackapps and register an app.

okurl --authorize stackexchange

Authorising StackExchange API
StackExchange Client Id: 7186
StackExchange Client Secret: 
Scopes: read_inbox,no_expiry,write_access,private_info

Scripted Example

https://github.com/yschimke/okurl/blob/master/commands/sorecent

#!/usr/bin/env okscript

import com.baulsupp.okurl.kotlin.*
import kotlinx.coroutines.experimental.runBlocking

data class Question(val tags: List<String>, val title: String, val answer_count: Int, val link: String, val creation_date: Long)

data class Questions(val items: List<Question>, val has_more: Boolean, val quota_max: Int, val quota_remaining: Int)

var questions = runBlocking {
  client.query<Questions>("https://api.stackexchange.com/2.2/questions/unanswered/my-tags?order=desc&sort=creation&site=stackoverflow");
}

val titleWidth = Math.max(50, terminalWidth - 80);
for (q in questions.items) {
  val time = epochSecondsToDate(q.creation_date)
  val url = q.link.replace("(.*)/.*".toRegex(), "$1");
  println("%${titleWidth}.${titleWidth}s %-18.18s %4.4s %-10s %s".format(q.title, q.tags.joinToString(), q.answer_count, time, url));
}

Shows recent stories matching your interested tags

$ sorecent
           How to use and print metrics in Finatra logback, metrics,     0 28/12/2017 https://stackoverflow.com/questions/48002554
Are there better ways to output text with twitter  python, python-3.x    0 28/12/2017 https://stackoverflow.com/questions/48002442
Using Retrofit + OkHttp + Gson the api returns htm android, kotlin, r    1 28/12/2017 https://stackoverflow.com/questions/48002223
Update / Add Key Hashes of an android app to Faceb android, facebook,    0 28/12/2017 https://stackoverflow.com/questions/48002077
    Invoking a common method on multiple receivers kotlin                0 28/12/2017 https://stackoverflow.com/questions/48001680
Graphcool-framework cli on local: &quot;Unknown fl reactjs, graphql,     0 28/12/2017 https://stackoverflow.com/questions/48001666
Can&#39;t update the Fragments in FragmentPagerAda android, android-f    1 28/12/2017 https://stackoverflow.com/questions/48001611
Clone this wiki locally