示例#1
0
        /// <summary>
        /// Get the next list of followers of the specified user.
        /// </summary>
        /// <param name="username"> The username of a user to retrieve his followers people. </param>
        public void GetNextFollowers(string username)
        {
            /* Max count = 200 */
            HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(apiUrl + "followers/list.json?cursor=" + nextCursor + "&skip_status=1&include_user_entities=false&count=200&screen_name=" + username);

            hwr.Method    = "GET";
            hwr.UserAgent = userAgent;
            hwr.Referer   = mobileUrl;

            hwr.CookieContainer = cookieContainer;

            hwr.Headers.Add("Authorization", bearerAuthorizationToken);
            hwr.Headers.Add("X-Csrf-Token", csrfToken);
            hwr.Headers.Add("X-Twitter-Auth-Type", "OAuth2Session");

            string response = "";

            using (var hwResponse = (HttpWebResponse)hwr.GetResponse())
            {
                using (var stream = hwResponse.GetResponseStream())
                {
                    using (var reader = new StreamReader(stream))
                    {
                        response = reader.ReadToEnd();
                    }
                }
            }

            JavaScriptSerializer deserializer    = new JavaScriptSerializer();
            TwitterResponse      twitterResponse = deserializer.Deserialize <TwitterResponse>(response);

            foreach (User user in twitterResponse.users)
            {
                TwitterUserInfo userInfo = new TwitterUserInfo();

                userInfo.ID             = user.id_str;
                userInfo.Username       = user.screen_name;
                userInfo.FollowersCount = user.followers_count.ToString();
                userInfo.FollowingCount = user.friends_count.ToString();

                UsersList.Add(userInfo);
            }

            nextCursor     = twitterResponse.next_cursor_str;
            HasNextRecords = (nextCursor != "0");
        }
示例#2
0
        /// <summary>
        /// Get some information about the specified usernames in the given list.
        /// </summary>
        /// <param name="usernameList"> A list of usernames that we will retrieve some information about it.
        /// The list must not contain more than 100 username. </param>
        public void GetUsersInfo(List <string> usernameList)
        {
            HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(apiUrl + "users/lookup.json?include_entities=false&screen_name=" + UsernameListToString(usernameList));

            hwr.Method    = "GET";
            hwr.UserAgent = userAgent;
            hwr.Referer   = mobileUrl;

            hwr.CookieContainer = cookieContainer;

            hwr.Headers.Add("Authorization", bearerAuthorizationToken);
            hwr.Headers.Add("X-Csrf-Token", csrfToken);
            hwr.Headers.Add("X-Twitter-Auth-Type", "OAuth2Session");

            string response = "";

            using (var hwResponse = (HttpWebResponse)hwr.GetResponse())
            {
                using (var stream = hwResponse.GetResponseStream())
                {
                    using (var reader = new StreamReader(stream))
                    {
                        response = reader.ReadToEnd();
                    }
                }
            }

            JavaScriptSerializer deserializer = new JavaScriptSerializer();
            List <User>          users        = deserializer.Deserialize <List <User> >(response);

            foreach (User user in users)
            {
                TwitterUserInfo userInfo = new TwitterUserInfo();

                userInfo.ID             = user.id_str;
                userInfo.Username       = user.screen_name;
                userInfo.FollowersCount = user.followers_count.ToString();
                userInfo.FollowingCount = user.friends_count.ToString();

                UsersList.Add(userInfo);
            }
        }