Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created May 4, 2012 18:01
Show Gist options
  • Select an option

  • Save jordanorelli/2596606 to your computer and use it in GitHub Desktop.

Select an option

Save jordanorelli/2596606 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"bufio"
"encoding/json"
"net/http"
)
func main() {
client := new(http.Client)
req, err := http.NewRequest("GET", "https://stream.twitter.com/1/statuses/filter.json?track=rain", nil)
if err != nil {
log.Fatal(err.Error())
}
req.SetBasicAuth("", "") // fill this in with your twitter username and password.
res, err := client.Do(req)
if err != nil {
log.Fatal(err.Error())
}
reader := bufio.NewReader(res.Body)
for {
line, err := reader.ReadBytes('\r')
if err != nil {
log.Fatal(err.Error())
}
var item struct{
Text string `json:"text"`
}
err = json.Unmarshal(line, &item)
if err != nil {
log.Fatal(err.Error())
}
log.Println(item.Text)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment