Esempio n. 1
0
        /// <summary>
        /// Posts a tweet for the given access credentials
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="accessToken"></param>
        /// <param name="accessTokenSecret"></param>
        /// <returns></returns>
        public string postTweet(string msg,string accessToken, string accessTokenSecret)
        {
            try
            {
                //Retrieve values from settings file
                var twitterConsumerKeySettings = ConfigurationManager.AppSettings["TwitterConsumerKey"];
                var twitterConsumerSecretSettings = ConfigurationManager.AppSettings["TwitterConsumerSecret"];

                string twitterConsumerKey = string.Empty;
                string twitterConsumerSecret = string.Empty;

                if (twitterConsumerKeySettings != null)
                    twitterConsumerKey = twitterConsumerKeySettings.ToString();
                if (twitterConsumerSecretSettings != null)
                    twitterConsumerSecret = twitterConsumerSecretSettings.ToString();

                TwitterClientInfo twitterClientInfo = new TwitterClientInfo();
                twitterClientInfo.ConsumerKey = twitterConsumerKey;
                twitterClientInfo.ConsumerSecret = twitterConsumerSecret;
                TwitterService twitterService = new TwitterService(twitterClientInfo);
                twitterService.AuthenticateWith(accessToken, accessTokenSecret);
                TwitterStatus ts = twitterService.SendTweet(msg);
                if (ts == null)
                {
                    throw new Exception("Invalid message or message already exists!");
                }
                return ts.Id.ToString();
            }
            catch
            {
                throw;
            }
        }
Esempio n. 2
0
 public TwitterService GetAuthenticatedService()
 {
     var twitterClientInfo = new TwitterClientInfo {ConsumerKey = ConsumerKey, ConsumerSecret = ConsumerSecret};
     twitterService = new TwitterService(twitterClientInfo);
     twitterService.AuthenticateWith(AccessToken, AccessTokenSecret);
     return twitterService;
 }
Esempio n. 3
0
 public void SetupTwitterClient()
 {
     TwitterClientInfo twitterClient = new TwitterClientInfo();
     twitterClient.ConsumerKey = "4FTAZV9NXphr04Stq9yIpQ";
     twitterClient.ConsumerSecret = "ZJ5yGtPrOcxsZQzsajnf8G8hDaP8QAwlRfEM0HUqHcc";
     twitterService = new TwitterService(twitterClient);
 }
Esempio n. 4
0
        public override void Post()
        {
            if ((String.IsNullOrEmpty(token = Config.TwitterAccessToken)
                || String.IsNullOrEmpty(tokenSecret = Config.TwitterTokenSecret))
                && !this.Auth())
            {
                App.Instance.AddError(Config.AUTHORIZATION_ERROR_EN, Config.TWITTER_TITLE);
                return;
            }
            else
            {
                //Authorize with the saved access token and secret
                TwitterClientInfo twitterClientInfo = new TwitterClientInfo();
                twitterClientInfo.ConsumerKey = ConsumerKey;
                twitterClientInfo.ConsumerSecret = ConsumerSecret;
                TwitterService twitterService = new TwitterService(twitterClientInfo);
                //twitterService.AuthenticateWith(token, tokenSecret);
            }

            try
            {
                this.PostTweet();
            }
            catch (Exception)
            {
                App.Instance.AddError(Config.TWITTER_ERROR, Config.TWITTER_TITLE);
            }
        }
Esempio n. 5
0
        public IQueryable<DisplayItem> GetSocialInfomation(string name)
        {
            IQueryable<DisplayItem> items = null;

            try
            {
                var twitterClientInfo = new TwitterClientInfo();
                twitterClientInfo.ConsumerKey = SettingsHelper.ConsumerKey;
                twitterClientInfo.ConsumerSecret = SettingsHelper.ConsumerSecret;

                var twitterService = new TwitterService(twitterClientInfo);
                twitterService.AuthenticateWith(SettingsHelper.AccessToken, SettingsHelper.AccessSecret);
                var searchOptions = new SearchOptions
                {
                    Q = name,
                };

                var searchResults = twitterService.Search(searchOptions);
                items = searchResults.Statuses.Select(x => ConvertToDataItem(x)).AsQueryable();
            }
            catch(Exception ex)
            {
                Logger.Error(ex);
            }

            return items;
        }
Esempio n. 6
0
 bool Auth()
 {
     this.fUsingSavedToken = false;
     TwitterClientInfo twitterClientInfo = new TwitterClientInfo();
     twitterClientInfo.ConsumerKey = ConsumerKey;
     twitterClientInfo.ConsumerSecret = ConsumerSecret;
     TwitterService twitterService = new TwitterService(twitterClientInfo);
     TwitterLoginDialog loginDialog = new TwitterLoginDialog(twitterService);
     System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(loginDialog);//f**k..
     if (loginDialog.ShowDialog() == true)
     {
         OAuthAccessToken accessToken = loginDialog.accessToken;
         try
         {
             twitterService.AuthenticateWith(
                 Config.TwitterAccessToken = this.token = accessToken.Token,
                 Config.TwitterTokenSecret = this.tokenSecret = accessToken.TokenSecret);
             return true;
         }
         catch
         {
         }
     }
     return false;
 }
Esempio n. 7
0
 private void InitializeNewSession()
 {
     _twitterClientInfo = new TwitterClientInfo();
     _twitterClientInfo.ConsumerKey = "2yeyhTAMl3Euzc2aXSlOA"; //TODO: get this value especially for adidas
     _twitterClientInfo.ConsumerSecret = "8yXVBamNBfd82hSbCbBNWPQvto0cjgqVjYuBbLXm0";
         //TODO: get this value especially for adidas
     _twitterService = new TwitterService(_twitterClientInfo);
     _requestToken = _twitterService.GetRequestToken();
 }
Esempio n. 8
0
        protected Twitter() {

            _service = new TwitterService();
            _service.AuthenticateWith("z8QjSW8DjdGulzV6HOiAPg", "cWlLPKci5I95ejzzbUlZqz5CXGDP0nXrTPpyuElgAg",
                                      "27216319-UClfYpcm0eqyrr7KhOHCMWzlIaIdU26hhinjVsnMm",
                                      "AzBjbgHXhQ2iLCfov5IHBZHZrOERba55Jf8bcHCICs");
            var t = new TwitterClientInfo();
            

        }
        public AuthorizeTwitter()
        {
            TwitterClientInfo twitterClientInfo = new TwitterClientInfo();
            twitterClientInfo.ConsumerKey = ConsumerKey; //Read ConsumerKey out of the app.config
            twitterClientInfo.ConsumerSecret = ConsumerSecret; //Read the ConsumerSecret out the app.config

            TwitterService twitterService = new TwitterService(twitterClientInfo);
            if (string.IsNullOrEmpty(AccessToken) || string.IsNullOrEmpty(AccessTokenSecret))
            {
                //Now we need the Token and TokenSecret

                //Firstly we need the RequestToken and the AuthorisationUrl
                OAuthRequestToken requestToken = twitterService.GetRequestToken();
                Uri authUrl = twitterService.GetAuthorizationUri(requestToken);

                //authUrl is just a URL we can open IE and paste it in if we want
                Console.WriteLine("Please Allow This App to send Tweets on your behalf");
                Process.Start(authUrl.ToString()); //Launches a browser that'll go to the AuthUrl.

                //Allow the App
                Console.WriteLine("Enter the PIN from the Browser:");
                string pin = Console.ReadLine();

                OAuthAccessToken accessToken = twitterService.GetAccessToken(requestToken, pin);

                string token = accessToken.Token; //Attach the Debugger and put a break point here
                string tokenSecret = accessToken.TokenSecret; //And another Breakpoint here

                Console.WriteLine("Write Down The AccessToken: " + token);
                Console.WriteLine("Write Down the AccessTokenSecret: " + tokenSecret);

            }

            twitterService.AuthenticateWith(AccessToken, AccessTokenSecret);
            //twitterService.SendTweet("A Simple Tweet from a Simple Twitter Client");
            //Console.WriteLine("Enter a Tweet");
            //string tweetMessage;

            //while (true)
            //{
            //    tweetMessage = Console.ReadLine();
            //    if (tweetMessage.ToLower() == "exit")
            //    {
            //        break;
            //    }
            //    twitterService.SendTweet(tweetMessage);
            //}

            var x = twitterService.ListFollowerIdsOf("_glynster_",-1);
        }
Esempio n. 10
0
        private TwitterService twitterService; //connection Twitter

        #endregion Fields

        #region Constructors

        public GameOver()
        {
            classementBG = Ressources.Content.Load<Texture2D>("Menu/Classement");
            gamewin = Ressources.Content.Load<Texture2D>("GameWin");

            #region Authentification Twitter

            TwitterClientInfo twitterClientInfo = new TwitterClientInfo();

            twitterClientInfo.ConsumerKey = "TF30IyeUwXRm1Xe38Qig"; //Read ConsumerKey out of the app.config

            twitterClientInfo.ConsumerSecret = "2gUJrzq3JtSSFLkwwaflRaFKxsYvCsDHu1WikEBRcM"; //Read the ConsumerSecret out the app.config

            twitterService = new TwitterService(twitterClientInfo);

            twitterService.AuthenticateWith("1515530498-gZaKFgEILJiF4rfFsbyURF1adSv6CpuqLzrZ9AO", "a0TyYuTBEqc68uq1GiaSCCGICc5MODIlABj0JvyM");
            #endregion
        }
Esempio n. 11
0
        public long GetTwitterFollowerCount(string vendorName)
        {
            long followerCount = 0;
            TwitterClientInfo twitterClientInfo = new TwitterClientInfo();
            twitterClientInfo.ConsumerKey = ConsumerKey; //Read ConsumerKey out of the app.config
            twitterClientInfo.ConsumerSecret = ConsumerSecret; //Read the ConsumerSecret out the app.config

            TwitterService twitterService = new TwitterService(twitterClientInfo);
            if (string.IsNullOrEmpty(AccessToken) || string.IsNullOrEmpty(AccessTokenSecret))
            {
                //Now we need the Token and TokenSecret

                //Firstly we need the RequestToken and the AuthorisationUrl
                OAuthRequestToken requestToken = twitterService.GetRequestToken();
                Uri authUrl = twitterService.GetAuthorizationUri(requestToken);

                //authUrl is just a URL we can open IE and paste it in if we want
                Console.WriteLine("Please Allow This App to send Tweets on your behalf");
                Process.Start(authUrl.ToString()); //Launches a browser that'll go to the AuthUrl.

                //Allow the App
                Console.WriteLine("Enter the PIN from the Browser:");
                string pin = Console.ReadLine();

                OAuthAccessToken accessToken = twitterService.GetAccessToken(requestToken, pin);

                string token = accessToken.Token; //Attach the Debugger and put a break point here
                string tokenSecret = accessToken.TokenSecret; //And another Breakpoint here

                Console.WriteLine("Write Down The AccessToken: " + token);
                Console.WriteLine("Write Down the AccessTokenSecret: " + tokenSecret);

            }

            twitterService.AuthenticateWith(AccessToken, AccessTokenSecret);
            //var status = twitterService.GetRateLimitStatus();
            var user = twitterService.GetUserProfileFor(vendorName);
            if (user != null)
            {
                followerCount = user.FollowersCount;
            }
            return followerCount;
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            TwitterClientInfo twitterClientInfo = new TwitterClientInfo();
            twitterClientInfo.ConsumerKey = ConsumerKey; //Read ConsumerKey out of the app.config
            twitterClientInfo.ConsumerSecret = ConsumerSecret; //Read the ConsumerSecret out the app.config

            TwitterService twitterService = new TwitterService(twitterClientInfo);

            if (string.IsNullOrEmpty(AccessToken) || string.IsNullOrEmpty(AccessTokenSecret))
            {
                //Now we need the Token and TokenSecret

                //Firstly we need the RequestToken and the AuthorisationUrl
                OAuthRequestToken requestToken = twitterService.GetRequestToken();
                string authUrl = twitterService.GetAuthorizationUri(requestToken).ToString();

                //authUrl is just a URL we can open IE and paste it in if we want
                Console.WriteLine("Please Allow This App to send Tweets on your behalf");
                //Process.Start(authUrl); //Launches a browser that'll go to the AuthUrl.

                //Allow the App
                Console.WriteLine("Enter the PIN from the Browser:");
                string pin = Console.ReadLine();

                OAuthAccessToken accessToken = twitterService.GetAccessToken(requestToken, pin);

                string token = accessToken.Token; //Attach the Debugger and put a break point here
                string tokenSecret = accessToken.TokenSecret; //And another Breakpoint here

                Console.WriteLine("Write Down The AccessToken: " + token);
                Console.WriteLine("Write Down the AccessTokenSecret: " + tokenSecret);
            }

            twitterService.AuthenticateWith(AccessToken, AccessTokenSecret);

            Console.WriteLine("Enter a Tweet");
            string tweetMessage;
            tweetMessage = Console.ReadLine();
            TwitterStatus twitterStatus = twitterService.SendTweet(tweetMessage);
        }
Esempio n. 13
0
        private static void SendTweet(string tweet)
        {
            if (DEBUG == false)
            {
                TwitterClientInfo twitterClientInfo = new TwitterClientInfo();
                twitterClientInfo.ConsumerKey = ConsumerKey; //Read ConsumerKey out of the app.config
                twitterClientInfo.ConsumerSecret = ConsumerSecret; //Read the ConsumerSecret out the app.config
                TwitterService twitterService = new TwitterService(twitterClientInfo);

                SendTweetOptions tweetOps = new SendTweetOptions() { Status = tweet };
                twitterService.AuthenticateWith(AccessToken, AccessTokenSecret);
                twitterService.SendTweet(tweetOps);
                var responseText = twitterService.Response.Response;
                Console.WriteLine("Tweet has been sent: " + tweet);
            }
            else
            {
                Console.WriteLine(tweet);
            }
        }
Esempio n. 14
0
        private void twitterToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            TwitterClientInfo twitterClientInfo = new TwitterClientInfo();
            twitterClientInfo.ConsumerKey = consumerKey; //Read ConsumerKey out of the app.config
            twitterClientInfo.ConsumerSecret = consumerSecret; //Read the ConsumerSecret out the app.config
            TwitterService twitterService = new TwitterService(consumerKey, consumerSecret);
            requestToken = twitterService.GetRequestToken();
            if (AdvancedSoftwareProject.Properties.Settings.Default.AccessToken != "" && AdvancedSoftwareProject.Properties.Settings.Default.AccessTokenSecret != "")
            {
                try
                {
                    twitterService.AuthenticateWith(AdvancedSoftwareProject.Properties.Settings.Default.AccessToken, AdvancedSoftwareProject.Properties.Settings.Default.AccessTokenSecret);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    authTwitter(twitterService);
                }
            }
            else
            {
                authTwitter(twitterService);
            }
            var options = new ListTweetsOnHomeTimelineOptions();
            var currentTweets = twitterService.ListTweetsOnHomeTimeline(options);
            List<TwitterStatus> tweets = currentTweets.ToList();
            //tweets[i].User.ScreenName

            //See https://github.com/danielcrenna/tweetsharp for more info on how to use tweets etc

            twitterFeed.DocumentText = "";
            string twitterHTML = "<div style = \"color:0099FF\">";

            for (int i = 0; i < tweets.Count; i++)
            {
                if (i != tweets.Count - 1)
                {
                    twitterHTML = twitterHTML + tweets[i].TextAsHtml + "<br><br>";
                }
                else
                {
                    twitterHTML = twitterHTML + tweets[i].TextAsHtml + "</div>";
                }
            }

            twitterFeed.DocumentText = twitterHTML;
        }
Esempio n. 15
0
 public TwitterService(TwitterClientInfo info) : base(info)
 {
 }