代码之家  ›  专栏  ›  技术社区  ›  Jason Jong

如何从TwitterAPI和趋势线中获取关注者数量

  •  13
  • Jason Jong  · 技术社区  · 14 年前

    我正在为Twitter的追随者数量编写一些报告,但是经过大量的搜索和尝试和错误之后,随着时间的推移,我无法获得追随者数量-特别是过去的追随者数量。

    我知道有一个API可以为追随者获取单独的用户ID,但这对我需要的东西来说太过分了,我每天都要调用它。理想情况下,如果我能通过一个日期,它可以返回追随者的数量将是伟大的。

    是否有人对此有任何经验以及API可能是什么?

    谢谢

    3 回复  |  直到 5 年前
        1
  •  17
  •   Community Dunja Lalic    7 年前

    Twittercounter.com API here

    http://api.twittercounter.com?twitter_id=813286&apikey=[api_key]
    

    {"version":"1.1","username":"BarackObama","url":"http:\/\/www.barackobama.com","avatar":"http:\/\/a1.twimg.com\/profile_images\/784227851\/BarackObama_twitter_photo_normal.jpg","followers_current":7420937,"date_updated":"2011-04-16","follow_days":"563","started_followers":"2264457","growth_since":5156480,"average_growth":"9166","tomorrow":"7430103","next_month":"7695917","followers_yesterday":7414507,"rank":"3","followers_2w_ago":7243541,"growth_since_2w":177396,"average_growth_2w":"12671","tomorrow_2w":"7433608","next_month_2w":"7801067","followersperdate":{"date2011-04-16":7420937,"date2011-04-15":7414507,"date2011-04-14":7400522,"date2011-04-13":7385729,"date2011-04-12":7370229,"date2011-04-11":7366548,"date2011-04-10":7349078,"date2011-04-09":7341737,"date2011-04-08":7325918,"date2011-04-07":7309609,"date2011-04-06":7306325,"date2011-04-05":7283591,"date2011-04-04":7269377,"date2011-04-03":7257596},"last_update":1302981230}
    

    here

        2
  •  30
  •   Jason Jong    6 年前

    http://api.twitter.com/1/users/show.json?user_id=12345
    

    https://dev.twitter.com/docs/api/1/get/users/show

    https://api.twitter.com/1.1/users/show.json?user_id=12345
    

    https://dev.twitter.com/docs/api/1.1/get/users/show

    https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-show
    
        3
  •  0
  •   Naresh    5 年前

    followers_count

    https://github.com/twitter/twitter-kit-ios

    //This is complete url 
    https://api.twitter.com/1.1/users/show.json?screen_name=screenName
    
    func getStatusesUserTimeline(accessToken:String) {
    
        let userId = "109*************6"
        let twitterClient = TWTRAPIClient(userID: userId)
        twitterClient.loadUser(withID: userId) { (user, error) in
            print(userId)
            print(user ?? "Empty user")
            if user != nil {
                var request = URLRequest(url: URL(string: "https://api.twitter.com/1.1/users/show.json?screen_name=screenName")!)
    
                request.httpMethod = "GET"
                request.setValue("Bearer "+accessToken, forHTTPHeaderField: "Authorization")
                print(request)
    
                let task = URLSession.shared.dataTask(with: request) { data, response, error in guard let data = data, error == nil else { // check for fundamental networking error
                    print("error=\(String(describing: error))")
                    return
                    }
    
                    if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 { // check for http errors
                        print("statusCode should be 200, but is \(httpStatus.statusCode)")
                        print("response = \(String(describing: response))")
                    }
    
                    do {
                        let response = try JSONSerialization.jsonObject(with: data, options: []) as! Dictionary<String,Any>
                        print(response)
                        // print((response["statuses"] as! Array<Any>).count)
    
                    } catch let error as NSError {
                        print(error)
                    }
                }
    
                task.resume()
    
            } else {
                print(error?.localizedDescription as Any)
            }
        }
    
    }