Ejemplo n.º 1
0
        /// <summary>
        /// Retrieves the user's friends using the parameter
        /// </summary>
        /// <param name="parameter">The parameter used to select the user</param>
        /// <param name="auth">The auth object</param>
        /// <returns></returns>
        private Friends GetFriends(string parameter, AuthObj auth)
        {
            List <User> tempList = new List <User>();
            long        cursor   = -1;

            while (cursor != 0)
            {
                var friends = new WebHandler(auth).TwitterGetRequest <Friends>(TwitterRequestBuilder.BuildRequest(RequestType.friendsObj, auth, parameter, "count=200", "cursor=" + cursor));
                tempList.AddRange(friends.Users);
                cursor  = friends.NextCursor;
                friends = null;
            }
            Friends result = new Friends();

            result.Users = tempList;
            tempList     = null;
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The method to retrieve tweets from a specific user.
        /// This method can retrieve as few tweets as 200 or as many as the constant TWEETS_TO_RETRIEVE (max.  3200)
        /// </summary>
        /// <param name="user">The user</param>
        /// <param name="auth">The auth object</param>
        /// <returns>A list of tweet posted by the user</returns>
        private List <Tweet> RetrieveTweets(User user, AuthObj auth)
        {
            List <Tweet> tweetList = new List <Tweet>();
            List <Tweet> tempList  = new List <Tweet>();

            if (!user.IsProtected)
            {
                long lastTweetID = 0;
                tempList.AddRange(new WebHandler(auth).TwitterGetRequest <List <Tweet> >(TwitterRequestBuilder.BuildRequest(RequestType.tweets, auth, "user_id=" + user.Id, "count=200")));
                if (tempList.Count != 0)
                {
                    lastTweetID = tempList.ElementAt(tempList.Count - 1).Id;
                    tweetList.AddRange(tempList.Where(x => !tweetList.Contains(x)));

                    while (tweetList.Count < Constants.TWEETS_TO_RETRIEVE)
                    {
                        tempList.AddRange(new WebHandler(auth).TwitterGetRequest <List <Tweet> >(TwitterRequestBuilder.BuildRequest(RequestType.tweets, auth, "user_id=" + user.Id, "count=200", "max_id=" + lastTweetID)));

                        if (tempList.Count == 0 || tempList.ElementAt(tempList.Count - 1).Id == lastTweetID)
                        {
                            break;
                        }

                        lastTweetID = tempList.ElementAt(tempList.Count - 1).Id;
                        tweetList.AddRange(tempList.Where(x => !tweetList.Contains(x)));
                    }
                }
            }

            tempList = null;

            return(tweetList);
        }