Ejemplo n.º 1
0
        // Goes through the list of tweets and assigns a person to a tweet
        // adds a number to the tweet which is the order the tweets were "written"
        private List<Tweet> CreateTweets(List<Person> people, List<string> tweetsInput)
        {
            var tweets = new List<Tweet>();
            var count = 0; // count to keep track of the order of the tweets

            foreach (var tweet in tweetsInput)
            {
                var separation = tweet.Split('>').ToArray();

                // check that the string has been split correctly by >
                // if it is not split correctly the tweets are not added
                if (separation.Length > 1)
                {
                    count++;

                    var actualTweet = new Tweet()
                    {
                        Person = people.FirstOrDefault(x => x.Name.Trim() == separation[0].Trim()),
                        Order = count
                    };


                    // check for 140 charachters
                    // if twwet in the character range, add the whole tweet to the list
                    if (separation[1].Length <= 140)
                    {
                        actualTweet.Description = separation[1];

                    }

                    // if the tweet is greater than 140 characters
                    else if (separation[1].Length > 140)
                    {
                        actualTweet.Description = separation[1].Substring(0, 140);
                    }

                    tweets.Add(actualTweet);
                }

            }

            return tweets;
        }
Ejemplo n.º 2
0
        public static void GetUserTimeline(string name, string AccessToken, int count, twitterButton caller)
        {
            Dictionary<string, string> headers = new Dictionary<string, string>();
            headers["Authorization"] = "Bearer " + AccessToken;

            WWW web = new WWW("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" + name + "&count=" + count + "&trim_user=1" + "&include_rts=0&exclude_replies=true&contributor_details=false", null, headers);

            while (!web.isDone)
            {
                Debug.Log("Grabbing timeline...");
            }

            //find user mentions
            List<string> mentions = extractData(web.text, ",\"user_mentions\":", ",\"urls\":");
            //remove if true
            string extractMe;
            if (ammendOutputText == null)
                extractMe = web.text;
            else
                extractMe = ammendOutputText;

            Debug.Log("Extracting profile data...");
            List<string> dateTime = extractData(extractMe, "{\"created_at\":\"", "\",\"id\":");
            List<string> text = extractData(extractMe, ",\"text\":\"", ",\"truncated\":");
            List<string> favs = extractData(extractMe, "\"favorite_count\":", ",\"entities\":");
            List<string> RTs = extractData(extractMe, "\"retweet_count\":", ",\"favorite_count\":");
            List<string> userID = extractData(extractMe, "\"user\":{\"id\":", "\"},\"geo\":");
            List<string> tweetID = extractData(extractMe, ",\"id\":", "\",\"text\":");
            List<Tweet> tweets = new List<Tweet>();

            //format datetime
            //
            //For each time a space is detected, 
            //do things with boop[2]

            for (int i = 0; i < text.Count; i++)
            {
                Tweet thisTweet = new Tweet();

                #region dateTime formating
                string temp = "";
                List<string> boop = new List<string>();
                for (int k = 0; k < dateTime[i].Length; k++)
                {
                    if (dateTime[i][k] != ' ')
                        temp += dateTime[i][k];
                    else
                    {
                        boop.Add(temp);
                        temp = "";
                    }

                    if (k == dateTime[i].Length - 1)
                        boop.Add(temp);
                }
                temp = "";
                List<string> doop = new List<string>();
                for (int k = 0; k < boop[3].Length; k++)
                {
                    if (boop[3][k] != ':')
                        temp += boop[3][k];
                    else
                    {
                        doop.Add(temp);
                        temp = "";
                    }

                    if (k == boop[3].Length - 1)
                        doop.Add(temp);
                }

                tw_DateTime time = new tw_DateTime();
                time.Weekday = boop[0];
                time.Month = boop[1];
                time.Day = boop[2];
                time.Hour = doop[0];
                time.Minute = doop[1];
                time.Second = doop[2];
                time.Year = boop[3];
                time.Offset = boop[4];
                #endregion

                thisTweet.dateTime = time;
                thisTweet.Text = text[i];
                thisTweet.UserID = userID[i].Substring(0, userID[i].IndexOf(",\"id_str"));
                thisTweet.RTs = int.Parse(RTs[i]);
                thisTweet.Favs = int.Parse(favs[i]);
                thisTweet.ID = tweetID[i].Substring(0, tweetID[i].IndexOf(",\"id_str"));

                tweets.Add(thisTweet);
            }
            caller.tweets = tweets;
            ammendOutputText = null;
        }
Ejemplo n.º 3
0
 public static IEnumerable <ITweet> GetLoggedUserTimeLine()
 {
     GetCredentialsFromConfig();
     Authorize();
     return(_userCredentials != null?_loggedUser.GetHomeTimeline(10) : Tweet.GetTweets());
 }
Ejemplo n.º 4
0
        private void CheckMessageType(string data)
        {
            try
            {
                Tweet tweet = JsonUtility.FromJson <Tweet>(data);
                if (tweet.text != null && tweet.id_str != null)
                {
                    messageType = StreamMessageType.Tweet;
                    return;
                }

                StreamEvent streamEvent = JsonUtility.FromJson <StreamEvent>(data);
                if (streamEvent.event_name != null)
                {
                    messageType = StreamMessageType.StreamEvent;
                    return;
                }

                FriendsList friendsList = JsonUtility.FromJson <FriendsList>(data);
                if (friendsList.friends != null)
                {
                    messageType = StreamMessageType.FriendsList;
                    return;
                }

                DirectMessage directMessage = JsonUtility.FromJson <DirectMessage>(data);
                if (directMessage.recipient_screen_name != null)
                {
                    messageType = StreamMessageType.DirectMessage;
                    return;
                }

                StatusDeletionNotice statusDeletionNotice = JsonUtility.FromJson <StatusDeletionNotice>(data);
                if (statusDeletionNotice.delete != null)
                {
                    messageType = StreamMessageType.StatusDeletionNotice;
                    return;
                }

                LocationDeletionNotice locationDeletionNotice = JsonUtility.FromJson <LocationDeletionNotice>(data);
                if (locationDeletionNotice.scrub_geo != null)
                {
                    messageType = StreamMessageType.LocationDeletionNotice;
                    return;
                }

                LimitNotice limitNotice = JsonUtility.FromJson <LimitNotice>(data);
                if (limitNotice.limit != null)
                {
                    messageType = StreamMessageType.LimitNotice;
                    return;
                }

                WithheldContentNotice withheldContentNotice = JsonUtility.FromJson <WithheldContentNotice>(data);
                if (withheldContentNotice.status_withheld != null || withheldContentNotice.user_withheld != null)
                {
                    messageType = StreamMessageType.WithheldContentNotice;
                    return;
                }

                DisconnectMessage disconnectMessage = JsonUtility.FromJson <DisconnectMessage>(data);
                if (disconnectMessage.disconnect != null)
                {
                    messageType = StreamMessageType.DisconnectMessage;
                    return;
                }

                StallWarning stallWarning = JsonUtility.FromJson <StallWarning>(data);
                if (stallWarning.warning != null)
                {
                    messageType = StreamMessageType.StallWarning;
                    return;
                }

                messageType = StreamMessageType.None;
                return;
            } catch (System.Exception e)
            {
                Debug.Log("CheckMessageType Error : " + e.ToString());
                messageType = StreamMessageType.None;
                return;
            }
        }