Esempio n. 1
0
        public static List<string> PostToReader(string _consumerKey, string _consumerSecret, string _accessToken, string _accessTokenSecret, string gUsername, string gPassword, bool chkTweets, bool chkFavorites, bool chkRetweets,  bool chkLinks, bool chkNoLinks)
        {
            List<string> res = new List<string>();
            GoogleReader gr = new GoogleReader(gUsername, gPassword);
            var serviceReader = new TwitterService(_consumerKey, _consumerSecret);
            serviceReader.AuthenticateWith(_accessToken, _accessTokenSecret);
            Regex urlfind = new Regex("((https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[A-Z0-9+&@#/%=~_|])", RegexOptions.IgnoreCase);

            List<TwitterStatus> mytweets =null;
            List<TwitterStatus> favorites=null;
            List<TwitterStatus> retweets =null;
            if (chkTweets)    mytweets  = serviceReader.ListTweetsOnUserTimeline(5).ToList();
            if (chkFavorites) favorites = serviceReader.ListFavoriteTweets(5).ToList();
            if (chkRetweets)  retweets  = serviceReader.ListRetweetsByMe(5).ToList();

            List<TwitterStatus> alltweets = new List<TwitterStatus>();
            if (mytweets != null) alltweets.AddRange(mytweets);
            if (favorites != null) alltweets.AddRange(favorites);
            if (retweets != null) alltweets.AddRange(retweets);

            foreach (var tweet in alltweets)
            {
                if (hassent(tweet.Id.ToString())) { continue; }
                Match thematch = urlfind.Match(tweet.Text);
                if (thematch.Success)
                {
                    if (chkLinks)
                    {
                        string theshorturl = thematch.Groups[1].Value;
                        string theurl = thematch.Groups[1].Value;
                        try
                        {
                            string longurlxml = c.DownloadString("http://api.unshort.me/?r=" + theurl);
                            Regex resUrl = new Regex("<resolvedURL>(.*?)</resolvedURL>");
                            Match resolved = resUrl.Match(longurlxml);
                            if (resolved.Success)
                            {
                                theurl = resolved.Groups[1].Value;
                            }
                        }
                        catch
                        {

                        }
                        string title;
                        string content = embed(theurl, out title);
                        gr.post(content, theurl, title, tweet.Text.Replace(theshorturl, "").Trim());
                        AddID(tweet.Id.ToString(), tweet.Text);
                    }

                }
                else if (chkNoLinks)
                {
                    gr.post("", "http://twitter.com/" + tweet.User.ScreenName + "/status/" + tweet.Id, "from twitter", tweet.Text.Trim());
                    AddID(tweet.Id.ToString(), tweet.Text);

                }
                res.Add( DateTime.Now.ToShortTimeString() + ": " + tweet.Text);
            }
            return res;
        }