skip to Main Content

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.

  1. Just want to confirm the code is right. Maybe I still can retrieve the info, but the code is incorrect.
  2. 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))
}

enter image description here

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search