Created
December 12, 2012 23:48
-
-
Save jordanorelli/4272795 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 ( | |
"bufio" | |
"encoding/json" | |
"log" | |
"net/http" | |
) | |
func main() { | |
username, password, client := "", "", new(http.Client) | |
req, err := http.NewRequest("GET", "https://stream.twitter.com/1/statuses/filter.json?track=tumblr", nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
req.SetBasicAuth(username, password) | |
res, err := client.Do(req) | |
if err != nil { | |
log.Fatal(err) | |
} | |
reader := bufio.NewReader(res.Body) | |
for { | |
line, err := reader.ReadBytes('\r') | |
if err != nil { | |
continue | |
} | |
var item struct { | |
Text string `json:"text"` | |
} | |
json.Unmarshal(line, &item) | |
log.Println(item.Text) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment