Open bep opened 9 years ago
+1
@bep I debug it and I understand how to enable throttling.
api := anaconda.NewTwitterApi(token, tokenSecret)
second := 30
duration := time.Duration(second) * time.Second
api.EnableThrottling(duration, 1)
EnableThrottling func takes 2 params
rate time.Duration
=> wait for x (seconds, minutes etc.)
bufferSize int64
=> run n request at the same time (for example 1)
if I set like this api.EnableThrottling(duration, 1)
,api execute only 1 request at the same time. Other requests have to wait for 30 seconds.
sample code:
func getAPI(token string, tokenSecret string) *anaconda.TwitterApi {
anaconda.SetConsumerKey("consumer")
anaconda.SetConsumerSecret("consumer secret")
api := anaconda.NewTwitterApi(token, tokenSecret)
second := 30
duration := time.Duration(second) * time.Second
api.EnableThrottling(duration, 1)
return api
}
func getTweets() {
api := getAPI("user access_token", "user access_token_secret")
v := url.Values{}
v.Set("count", "5")
for i := 0; i < 2; i++ {
tweets, err := api.GetHomeTimeline(v)
if err != nil {
fmt.Println(err.Error())
}
for _, item := range tweets {
fmt.Println(item.Text)
}
fmt.Println("***************************")
fmt.Println("***************************")
}
}
+1
SetRate()
may not work either after the throttling is enabled: https://github.com/ChimeraCoder/tokenbucket/issues/6
See
https://github.com/ChimeraCoder/anaconda/blob/master/README#L83-L92
At this point, no
bucket
is set.Correct should maybe to use
EnableThrottling
andDisableThrottling
?Maybe also add a note about
bufferSize
?