From b814368d3c31ac295e6d6fc33db03c40fab141b8 Mon Sep 17 00:00:00 2001 From: Sergey Tolmachev Date: Sat, 30 Mar 2019 12:05:23 +0300 Subject: [PATCH] added retweeters ids method --- tweets.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tweets.go b/tweets.go index 0baf4b2..5841838 100644 --- a/tweets.go +++ b/tweets.go @@ -6,6 +6,11 @@ import ( "strconv" ) +type RetweetersIdsPage struct { + Ids []int64 + Error error +} + func (a TwitterApi) GetTweet(id int64, v url.Values) (tweet Tweet, err error) { v = cleanValues(v) v.Set("id", strconv.FormatInt(id, 10)) @@ -36,6 +41,40 @@ func (a TwitterApi) GetRetweets(id int64, v url.Values) (tweets []Tweet, err err return tweets, (<-response_ch).err } +// Like GetRetweetersIdsList, but returns a channel instead of a cursor and pre-fetches the remaining results +// This channel is closed once all values have been fetched +func (a TwitterApi) GetRetweetersIdsListAll(v url.Values) (result chan RetweetersIdsPage) { + result = make(chan RetweetersIdsPage) + + v = cleanValues(v) + go func(a TwitterApi, v url.Values, result chan RetweetersIdsPage) { + // Cursor defaults to the first page ("-1") + next_cursor := "-1" + for { + v.Set("cursor", next_cursor) + c, err := a.GetRetweetersIdsList(v) + + // throttledQuery() handles all rate-limiting errors + // if GetFollowersList() returns an error, it must be a different kind of error + + result <- RetweetersIdsPage{c.Ids, err} + + next_cursor = c.Next_cursor_str + if err != nil || next_cursor == "0" { + close(result) + break + } + } + }(a, v, result) + return result +} + +func (a TwitterApi) GetRetweetersIdsList(v url.Values) (c Cursor, err error) { + response_ch := make(chan response) + a.queryQueue <- query{a.baseUrl + "/statuses/retweeters/ids.json", v, &c, _GET, response_ch} + return c, (<-response_ch).err +} + //PostTweet will create a tweet with the specified status message func (a TwitterApi) PostTweet(status string, v url.Values) (tweet Tweet, err error) { v = cleanValues(v)