func main() { var ( err error client *twittergo.Client req *http.Request resp *twittergo.APIResponse user *twittergo.User ) client, err = LoadCredentials() if err != nil { fmt.Printf("Could not parse CREDENTIALS file: %v\n", err) os.Exit(1) } req, err = http.NewRequest("GET", "/1.1/account/verify_credentials.json", nil) if err != nil { fmt.Printf("Could not parse request: %v\n", err) os.Exit(1) } resp, err = client.SendRequest(req) if err != nil { fmt.Printf("Could not send request: %v\n", err) os.Exit(1) } user = &twittergo.User{} err = resp.Parse(user) if err != nil { fmt.Printf("Problem parsing response: %v\n", err) os.Exit(1) } fmt.Printf("ID: %v\n", user.Id()) fmt.Printf("Name: %v\n", user.Name()) if resp.HasRateLimit() { fmt.Printf("Rate limit: %v\n", resp.RateLimit()) fmt.Printf("Rate limit remaining: %v\n", resp.RateLimitRemaining()) fmt.Printf("Rate limit reset: %v\n", resp.RateLimitReset()) } else { fmt.Printf("Could not parse rate limit from response.\n") } }
func (tw *RealTwitterWrapper) RespondToTweet(tweet *twittergo.Tweet, message string) { var ( err error user twittergo.User req *http.Request resp *twittergo.APIResponse ) user = tweet.User() data := url.Values{} // set status status := fmt.Sprintf("@%v %v", user.ScreenName(), message) data.Set("status", status) // set in_reply_to_status_id status_id := fmt.Sprintf("%d", tweet.Id()) data.Set("in_reply_to_status_id", status_id) log.Printf("Set status '%v' to '%v' in reply to %v", status, user.ScreenName(), status_id) body := strings.NewReader(data.Encode()) req, err = http.NewRequest("POST", "/1.1/statuses/update.json", body) if err != nil { log.Fatalf("Could not parse request: %v\n", err) } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") resp, err = tw.client.SendRequest(req) if err != nil { log.Fatalf("Could not send request: %v\n", err) } tweet = &twittergo.Tweet{} err = resp.Parse(tweet) if err != nil { log.Fatalf("Problem parsing response: %v\n", err) } }