Created
May 4, 2012 18:01
-
-
Save jordanorelli/2596606 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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