func main() { stream := make(chan *twitterstream.Tweet) client := twitterstream.NewClient("TWITTER USER", "TWITTER PASSWORD") err := client.Follow([]int64{8865192 /*USER IDs TO FOLLOW*/}, stream) if err != nil { println(err.String()) } for { tw := <-stream // if it's not a reply if tw.In_reply_to_user_id == 0 { // and not a retweet if rtRegExp.FindString(tw.Text) == "" { // this is a valid tweet to export // check if it's got links us := urlRegExp.FindAllString(tw.Text, -1) if len(us) > 0 { PostFacebookLink(tw.Text, us) } else { PostFacebookStatus(tw.Text) } } } } }
func main() { client := twitterstream.NewClient("username", "password") err := client.Sample() if err != nil { println(err.String()) } for { tw := <-client.Stream println(tw.User.Screen_name, ": ", tw.Text) } }
func main() { stream := make(chan *twitterstream.Tweet) client := twitterstream.NewClient("username", "password") err := client.Track([]string{"miley"}, stream) if err != nil { println(err.String()) } for { tw := <-stream println(tw.User.Screen_name, ": ", tw.Text) } }
func main() { stream := make(chan *twitterstream.Tweet) client := twitterstream.NewClient("Username", "Password") err := client.Sample(stream) if err != nil { println(err) } for { tw := <-stream println(tw.User.Screen_name, ": ", tw.Text) } }
func main() { // stream Twitter stream := make(chan *twitterstream.Tweet) client := twitterstream.NewClient(username, password) tracks := strings.Split(*track, ",") err := client.Track(tracks, stream) if err != nil { println(err.String()) } fmt.Fprintf(os.Stderr, "track = %v\n", *track) // process the tweets for { tw := (<-stream).Text if !*printOnly { process(tw) } else { fmt.Println(tw) } } }
func main() { flag.Parse() if len(*twitterUsername) == 0 || len(*twitterPassword) == 0 || len(*streamSpigotHostname) == 0 || len(*streamSpigotSecret) == 0 { flag.Usage() return } baseUrl := fmt.Sprintf("http://%s/bird-feeder/pinger/", *streamSpigotHostname) followingUrl := fmt.Sprintf("%sfollowing?secret=%s", baseUrl, url.QueryEscape(*streamSpigotSecret)) pingUrl := baseUrl + "ping" resp, getErr := http.Get(followingUrl) if getErr != nil { fmt.Printf("Got error %s when trying to fetch following list\n", getErr) os.Exit(1) } if resp.StatusCode != 200 { fmt.Printf(" ...got HTTP status %d when trying to fetch following list\n", resp.StatusCode) return } contents, readErr := ioutil.ReadAll(resp.Body) if readErr != nil { resp.Body.Close() fmt.Printf("Got error %s when trying to read following list\n", readErr) os.Exit(1) } resp.Body.Close() var followingUserIds []int64 jsonErr := json.Unmarshal(contents, &followingUserIds) if jsonErr != nil { fmt.Printf("Got error %s when trying to decode JSON\n", jsonErr) os.Exit(1) } followingUserIdMap := make(map[int64]bool) for _, v := range followingUserIds { followingUserIdMap[v] = true } fmt.Printf("Tracking updates for %d users...\n", len(followingUserIds)) stream := make(chan *twitterstream.Tweet) client := twitterstream.NewClient(*twitterUsername, *twitterPassword) err := client.Follow(followingUserIds, stream) if err != nil { fmt.Println(err.String()) } for { tweet := <-stream // We ignore tweets that come from users that we're not following (the // Streaming API will also notify when tweets of theirs are retweeted or // replied to). if _, inMap := followingUserIdMap[tweet.User.Id]; inMap { go pingUser(tweet.User.Id, pingUrl) } } }