ChimeraCoder / anaconda

A Go client library for the Twitter 1.1 API
MIT License
1.14k stars 247 forks source link

Throttle info in README is wrong #81

Open bep opened 9 years ago

bep commented 9 years ago

See

https://github.com/ChimeraCoder/anaconda/blob/master/README#L83-L92

At this point, no bucket is set.

Correct should maybe to use EnableThrottling and DisableThrottling?

Maybe also add a note about bufferSize?

melihmucuk commented 8 years ago

+1

melihmucuk commented 8 years ago

@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("***************************")
    }
}
aggrolite commented 8 years ago

+1

aggrolite commented 8 years ago

SetRate() may not work either after the throttling is enabled: https://github.com/ChimeraCoder/tokenbucket/issues/6