Can’t retrieve user followers via accessing Twitter API. I couldn’t really figure out why it’s not working before I found out they removed followers from Basic access.
- Just want to confirm the code is right. Maybe I still can retrieve the info, but the code is incorrect.
- If it is indeed due to the endpoints removed. Any ideas how I can work around this barrier? Via other endpoints? I don’t know; any suggestion, really.
package main
import (
"encoding/json"
"flag"
"fmt"
"net/url"
"time"
"github.com/cvcio/twitter"
)
func main() {
consumerKey := flag.String("consumer-key", "", "twitter API consumer key")
consumerSecret := flag.String("consumer-secret", "", "twitter API consumer secret")
id := flag.String("id", "", "user id")
flag.Parse()
start := time.Now()
api, err := twitter.NewTwitter(*consumerKey, *consumerSecret)
if err != nil {
panic(err)
}
v := url.Values{}
v.Add("max_results", "1000")
followers, _ := api.GetUserFollowers(*id, v)
for {
r, ok := <-followers
if !ok {
break
}
b, err := json.Marshal(r.Data)
if err != nil {
panic(err)
}
var data []*twitter.User
json.Unmarshal(b, &data)
for _, v := range data {
fmt.Printf("%s,%s,%sn", v.ID, v.UserName, v.Name)
}
fmt.Println()
fmt.Printf("Result Count: %d Next Token: %sn", r.Meta.ResultCount, r.Meta.NextToken)
}
end := time.Now()
fmt.Printf("Done in %s", end.Sub(start))
}
2
Answers
I’m sorry to inform you that they have indeed removed these interfaces. There is no better way to solve it. Unless you upgrade your paid package. Your code has no errors.
I’m in the same boat. It seems that the GET /2/users/:id/following feature in Twitter API v2 is only available on the enterprise tier after the update.