Groovy web console

subscribe to the feed Subscribe
to this
site

Twitter Groovy Basic Auth

Published 10 years ago by scott@thirstyhead.com with tags twitter groovy basic authentication
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def addr = "http://twitter.com/statuses/friends_timeline.atom"
//NOTE: Obviously, set the username and password to your values
def authString = "username:password".getBytes().encodeBase64().toString()
def conn = addr.toURL().openConnection()
conn.setRequestProperty("Authorization", "Basic ${authString}")
if(conn.responseCode == 200){
  def feed = new XmlSlurper().parseText(conn.content.text)
  feed.entry.each{entry->    
    println entry.author.name
    println entry.title
    println "-"*20
  }
}else{
  println "Something bad happened."
  println "${conn.responseCode}: ${conn.responseMessage}" 
}