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

Twitter

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

Twitter

Authentication (OkUrl App)

$ okurl --authorize twitter
Authorising Twitter API
Consumer Key [O2h47Hy8FNsz956UNmXJpXJNW]:
Consumer Secret [**************************************************]:

Authentication (PIN - OOB)

This will launch a web browser and ask you to approve access for OkUrl or another client, then give you a pin to enter.

$ okurl --authorize twitter --pin
Authorising Twitter API
Authorise by entering the PIN through a web browser
Enter PIN: 

Twitter PIN

Queries

$ okurl 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=realDonaldTrump' | jq .
[
  {
    "created_at": "Sun May 15 21:26:39 +0000 2016",
    "id": 731959001143988200,
    "id_str": "731959001143988229",
    "text": "Thank you Georgia! See you soon!\n#Trump2016 https://t.co/8yFd6qA4rD",

Images will be opened in Preview.app or inline in iTerm

$ okurl https://pbs.twimg.com/media/Cihw0Z0XEAE58rf.jpg

Open images related to the twitter search term "euros"

$ ./commands/tweetsearch boris johnson
scotlandbest        : RT @angelneptustar: Now @Theresa_May has lost her guardians Hill & Timothy, who decided everything for her, have Remainer civil servants #H…
scrapegroat         : Feels like it's been a little while since Boris Johnson has grossly humiliated himself and his country. Sweepstake on the date of his next hilarious* blunder*?
angelneptustar      : Now @Theresa_May has lost her guardians Hill & Timothy, who decided everything for her, have Remainer civil servants #Heywood & Robbins taken over?  #May needs to B told what to say....says @ShippersUnbound in FALLOUT. @Borisjohnson #boris johnson #borisjohnson #Brexit https://t.co/Vof7qqfXPe
#!/usr/bin/env okscript

import com.baulsupp.okurl.kotlin.*
import com.baulsupp.okurl.services.twitter.model.*
import kotlinx.coroutines.experimental.runBlocking
import java.net.URLEncoder

runBlocking {
    var argumentString = arguments.joinToString("+") { URLEncoder.encode(it, "UTF-8") };

    val a = client.query<SearchResults>("https://api.twitter.com/1.1/search/tweets.json?tweet_mode=extended&q=" + argumentString)

    a.statuses.forEach { tweet ->
      println("%-20s: %s".format(tweet.user.screen_name, tweet.full_text))

      tweet.entities?.media?.firstOrNull()?.media_url_https?.let {
        show(it + ":thumb")
        println()
      }
    }
}
Clone this wiki locally