Skip to content

Instantly share code, notes, and snippets.

@x86128
Created May 13, 2018 17:36
Show Gist options
  • Save x86128/3a072272ce3b2356bd7286700ecfe8d6 to your computer and use it in GitHub Desktop.
Save x86128/3a072272ce3b2356bd7286700ecfe8d6 to your computer and use it in GitHub Desktop.
Twitter list
req = require 'request'
fs = require 'fs'
username = 'x86128'
keys = JSON.parse fs.readFileSync 'keys.json'
auth = Buffer.from("#{keys.key}:#{keys.secret}").toString('base64')
get_auth_token = (keys, cb) ->
opts =
url: 'https://api.twitter.com/oauth2/token'
headers:
'Authorization': "Basic #{Buffer.from("#{keys.key}:#{keys.secret}").toString('base64')}"
form:
grant_type: 'client_credentials'
req.post opts, (err, resp, body) =>
if not err
token = JSON.parse body
cb(token)
get_twits = (token, cb) ->
opts =
url: 'https://api.twitter.com/1.1/statuses/user_timeline.json'
qs:
exclude_replies: true,
screen_name: username,
tweet_mode: 'extended',
count: 3200
headers:
'Authorization' : "Bearer #{token.access_token}"
req.get opts, (err,res,body) =>
if not err
cb(JSON.parse body)
get_auth_token keys, (token) ->
get_twits token, (twits) ->
id_last = ''
id_min = ''
console.log "| ID | DATE | TEXT |"
console.log "|---|---|---|"
for t in twits
console.log '| ',t.id_str,'| ', t.created_at,'| ', t.full_text, ' |'
id_min = t.id_str if id_min == ''
id_last = id_min if id_last == ''
if t.id_str < id_min
id_last = id_min
id_min = t.id_str
console.log id_last, id_min
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment