protected override void OnStart(string[] args) { // Arrange var controller = new TwitterController(); var token = controller.GetAuthToken(OAuthConsumerKey, OAuthConsumerSecret); var applicationTweets = controller.GetApplicationTweets(token, HashTag); string lastId = "0"; using (var sr = new StreamReader(FileName)) { lastId = sr.ReadLine(); } foreach (var applicationTweet in applicationTweets) { var tweet = new SendTweetOptions { Status = String.Format("@{0} Thanks for applying! You'll receive a confirmation email shortly.", applicationTweet.in_reply_to_screen_name), InReplyToStatusId = Int64.Parse(applicationTweet.id_str), }; var actual = controller.PostTweet(token, tweet); lastId = applicationTweet.id_str; } using (var sw = new StreamWriter(FileName, false, Encoding.ASCII)) { sw.WriteLine(lastId); } }
/// <summary> /// Send a tweet /// </summary> /// <param name="text">The content of the tweet</param> /// <returns>True if the tweet was successfully send otherwise false</returns> public bool tweet(string text) { bool success; SendTweetOptions options; TwitterStatus status; try { success = false; if (service != null) { options = new SendTweetOptions(); options.Status = text; status = service.SendTweet(options); if (status != null) { if (string.IsNullOrEmpty(status.IdStr) == false) { success = true; } } } return(success); } catch (Exception) { throw; } }
public void Tweet(string message, string hashTag, string picture) { if (CalcurateTweetLength(message, hashTag, picture) > 140) { throw new ArgumentException("文字数が多すぎます。"); } if (twitterService_ == null) { twitterService_ = new TwitterService(consumerKey_, consumerSecret_); twitterService_.AuthenticateWith(accessToken_, accessTokenSecret_); } var str = CreateTweetText(message, hashTag); if (picture != null) { SendTweetWithMediaOptions opt = new SendTweetWithMediaOptions(); using (var fs = new FileStream(picture, FileMode.Open, FileAccess.Read, FileShare.Read)) { opt.Images = new Dictionary <string, Stream> { { "image", fs } }; opt.Status = str; twitterService_.SendTweetWithMedia(opt); } } else { var opt = new SendTweetOptions(); opt.Status = str; twitterService_.SendTweet(opt); } }
public ActionResult UpdateRoBenFranklin() { List <string> model = new List <string>(); MarkovChain chain = new MarkovChain(100); FeeDText(chain); var service = new TwitterService("K47rQlImnCUoRFTnVtB2yJfaN", "5Wv4cjWfRsWZO5LuWLxldCh0AU8GBYQVAyfODnhzhkGEp5r1BG"); service.AuthenticateWith("722475012255563776-Ukvwm59B9U94AGo014K0TJA2h5zUWot", "v1qWB8Bs9KPZHyQccHozpsGb85wHrRGYW76lJEsdCd6Y9"); for (int i = 0; i < 15; i++) { string generate = chain.ToString(25); while (generate.Length < 140) { generate += " " + chain.ToString(25); } string msg = generate.Substring(0, 140); var tweet = new SendTweetOptions { Status = msg }; service.SendTweet(tweet); model.Add(msg); } return(View(model)); }
public void SendTweet(String status) { var tweetoptions = new SendTweetOptions(); tweetoptions.Status = status; service.SendTweet(tweetoptions); }
public void PostTweet_ShouldOnlyReplyOnce_Succeeds() { // Arrange var controller = new TwitterController(); var token = controller.GetAuthToken(OAuthConsumerKey, OAuthConsumerSecret); var applicationTweets = controller.GetApplicationTweets(token, HashTag); string lastId = "0"; foreach (var applicationTweet in applicationTweets) { var tweet = new SendTweetOptions { Status = String.Format("@{0} Thanks for applying! You'll receive a confirmation email shortly.", applicationTweet.in_reply_to_screen_name), InReplyToStatusId = Int64.Parse(applicationTweet.id_str), }; var actual = controller.PostTweet(token, tweet); lastId = applicationTweet.id_str; Assert.IsNotNull(actual); } applicationTweets = controller.GetApplicationTweets(token, HashTag, lastId); Assert.IsTrue(!applicationTweets.Any()); }
private static void SendTweet(string status) { var sendTweetOptions = new SendTweetOptions { Status = status }; service.SendTweet(sendTweetOptions); }
private void SendMsgTwitter() { var service = TwitterHelper.Authentication(); var opts = new SendTweetOptions { Status = Message.Text }; service.SendTweet(opts, (tweets, response) => { }); }
private void ShareOnTwitter(LeaderboardInfo leaderboardInfo) { var tweetOptions = new SendTweetOptions { Status = _tweetMessageService.GetTwitterMessage(leaderboardInfo.Score) }; _twitterService.SendTweet(tweetOptions); }
void CallBackVerifiedResponse(OAuthAccessToken at, TwitterResponse response) { if (at != null) { IsolatedSettingsHelper.SetValue <string>("ttoken", at.Token); IsolatedSettingsHelper.SetValue <string>("ttokensec", at.TokenSecret); try { Dispatcher.BeginInvoke(() => { ////////////////////////// OAuthCredentials credentials = new OAuthCredentials(); credentials.Type = OAuthType.ProtectedResource; credentials.SignatureMethod = OAuthSignatureMethod.HmacSha1; credentials.ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader; credentials.ConsumerKey = TwitterSettings.ConsumerKey; credentials.ConsumerSecret = TwitterSettings.ConsumerKeySecret; credentials.Token = at.Token; credentials.TokenSecret = at.TokenSecret; credentials.Version = "1.1"; //credentials.ClientUsername = ""; credentials.CallbackUrl = "none"; var service = new TwitterService(TwitterSettings.ConsumerKey, TwitterSettings.ConsumerKeySecret); service.AuthenticateWith(at.Token, at.TokenSecret); SendTweetOptions st = new SendTweetOptions(); st.Status = "post"; service.SendTweet(new SendTweetOptions { Status = post }, CallBackVerifiedResponse1); /////////////////////////////// }); } catch { System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show("An error occurred,please try again."); return; }); } } else { System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show("Wrong pin please try again", "Error", MessageBoxButton.OK); GetTwitterToken(); }); } }
public void SendTweet(string message) { SendTweetOptions options = new SendTweetOptions() { Status = message }; Service.SendTweet(options); }
// POST api/tweet public TwitterStatus PostTweet(TwitterAuthTokenModel tokenModel, SendTweetOptions tweet) { TwitterService service = new TwitterService(OAuthConsumerKey, OAuthConsumerSecret); service.AuthenticateWith("2547463968-WK7dpHLhbwSkFn5ahxweGreCdqFQ4Yw9fnMDWQ7", "SriZkL4wipjDr74DsmjBbg6OSFSxNicm9z0sPpu9UbJd3"); var ret = service.SendTweet(tweet); return(ret); }
private void btnYeniTweetGonder_Click(object sender, EventArgs e) { string text = txtYeniTweet.Text; SendTweetOptions opt = new SendTweetOptions(); opt.Status = text; _Service.SendTweet(opt); }
/// <summary> /// Send new tweet / status update /// </summary> private void btnSend_tweet_Click(object sender, RoutedEventArgs e) { SendTweetOptions options = new SendTweetOptions(); options.Status = txtTweet.Text; service.SendTweet(options); MessageBox.Show("Tweet sent!"); txtTweet.Text = ""; ToggleNewTweet(); }
public static void SendMessage(string message, bool tweet = false) { if (tweet) { SendTweetOptions options = new SendTweetOptions(); options.Status = string.Format("[MythicFeed] " + message + " @{0}", user.ScreenName); service.SendTweet(options); } Console.WriteLine(message); }
public void ProcessTweet(string status, string userName, string Nick) { var twitterSecret = new TwitterSecretData(userName, Nick); var service = new TwitterService(twitterSecret._OAuthConsumerKey, twitterSecret._OAuthConsumerSecret); service.AuthenticateWith(twitterSecret._OAuthAccessToken, twitterSecret._OAuthAccessTokenSecret); var sendTweetOptions = new SendTweetOptions(); sendTweetOptions.Status = status; service.SendTweet(sendTweetOptions); }
public async Task ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages) { Trace.TraceInformation("\n"); Trace.TraceInformation("........ProcessEventsAsync........"); foreach (EventData eventData in messages) { try { string jsonString = Encoding.UTF8.GetString(eventData.GetBytes()); Trace.TraceInformation(string.Format("Message received at '{0}'. Partition: '{1}'", eventData.EnqueuedTimeUtc.ToLocalTime(), this.partitionContext.Lease.PartitionId)); Trace.TraceInformation(string.Format("-->Raw Data: '{0}'", jsonString)); SensorEvent newSensorEvent = this.DeserializeEventData(jsonString); Trace.TraceInformation(string.Format("-->Serialized Data: '{0}', '{1}', '{2}', '{3}'", newSensorEvent.deviceid, newSensorEvent.currenttemp, newSensorEvent.gassense, newSensorEvent.flamesense)); /* Send command to IoT device.*/ // Turn off heater device. string commandParameterNew = "{\"Name\":\"TurnHeaterOff\",\"Parameters\":{\"reason\":" + 1 + "}}"; Trace.TraceInformation("Turning heater off: '{0}'", newSensorEvent.deviceid); Trace.TraceInformation("New Command Parameter: '{0}'", commandParameterNew); await WorkerRole.iotHubServiceClient.SendAsync(newSensorEvent.deviceid, new Microsoft.Azure.Devices.Message(Encoding.UTF8.GetBytes(commandParameterNew))); if (DateTime.Now - lastTweet > new TimeSpan(0, 5, 0)) // One tweet per 5 min { // Tweeting here string consumerKey = ConfigurationManager.AppSettings["Twitter.ConsumerKey"]; string consumerSecret = ConfigurationManager.AppSettings["Twitter.ConsumerSecret"]; string accessToken = ConfigurationManager.AppSettings["Twitter.AccessToken"]; string accessSecret = ConfigurationManager.AppSettings["Twitter.AccessSecret"]; // Obtain keys by registering your app on https://dev.twitter.com/apps or https://apps.twitter.com/ var service = new TwitterService(consumerKey, consumerSecret); service.AuthenticateWith(accessToken, accessSecret); SendTweetOptions x = new SendTweetOptions(); x.Status = string.Format("Gas leak detected from Smart heater! (Auto-generated messsage from Azure Stream Analytics)"); service.SendTweet(x); lastTweet = DateTime.Now; } } catch (Exception ex) { Trace.TraceInformation("Error in ProssEventsAsync -- {0}\n", ex.Message); } } await context.CheckpointAsync(); }
public void ProcessReply(string statusId, string userName, string screenName, string Nick, string text) { var twitterSecret = new TwitterSecretData(userName, Nick); var service = new TwitterService(twitterSecret._OAuthConsumerKey, twitterSecret._OAuthConsumerSecret); service.AuthenticateWith(twitterSecret._OAuthAccessToken, twitterSecret._OAuthAccessTokenSecret); var sendTweetOptions = new SendTweetOptions(); sendTweetOptions.Status = "@" + screenName + " " + text; sendTweetOptions.InReplyToStatusId = Convert.ToInt64(statusId); service.SendTweet(sendTweetOptions); }
public static void SendMessage(string Message, bool bounce = false) { if (bounce) { Console.WriteLine(Message); } SendTweetOptions options = new SendTweetOptions(); options.Status = string.Format("[MythicFeed] " + Message + " @{0}", user.ScreenName); service.SendTweet(options); }
public void ShareOnTwitter(LeaderboardInfo leaderboardInfo) { if (!_authenticated) { return; } var tweetOptions = new SendTweetOptions { Status = _tweetMessageService.GetTwitterMessage(leaderboardInfo.Score) }; _twitterService.SendTweet(tweetOptions); }
static void PostTweet(string Text) { var service = new TwitterService("key", "secret key"); service.AuthenticateWith("token", "secret token"); Console.WriteLine("Authenticated"); SendTweetOptions tweet = new SendTweetOptions(); Console.WriteLine("Created Tweet"); tweet.Status = Text; service.SendTweet(tweet); Console.WriteLine("Tweet Sent"); }
public void WriteTweet(string text) { var requestOptions = new SendTweetOptions { Status = text }; _twitterService.SendTweet(requestOptions, (tweet, response) => { if (response.StatusCode != HttpStatusCode.OK) { throw new TwitterClientException(response.Error.Message); } }); }
public static bool SendTweet(TwitterService service, string status, long inReplyToStatusId) { var sendoptions = new SendTweetOptions(); sendoptions.Status = status; sendoptions.InReplyToStatusId = inReplyToStatusId; var response = service.SendTweet(sendoptions); if (response == null) { Console.WriteLine("ERROR SENDING TWEET! Possible duplicate!"); return(false); } return(true); }
static void Main() { // https://github.com/danielcrenna/tweetsharp Console.WriteLine("Twitter API"); try { var consumerKey = ConfigurationManager.AppSettings["ConsumerKey"]; var consumerSecret = ConfigurationManager.AppSettings["ConsumerSecret"]; var token = ConfigurationManager.AppSettings["Token"]; var tokenSecret = ConfigurationManager.AppSettings["TokenSecret"]; var service = new TwitterService(consumerKey, consumerSecret); service.AuthenticateWith(token, tokenSecret); var options = new SendTweetOptions { Status = string.Format("{0} {1}", DateTime.Now, "C# Twitter API Test") }; Console.WriteLine("Tweet status: {0}", options.Status); var status = service.SendTweet(options); Console.WriteLine( status.Id > 0 ? "Tweet looks good, id greater than zero: {0}" : "Issue tweeting, returned id: {0}", status.Id); Console.WriteLine("Read tweets from Home Timeline"); var tweets = service.ListTweetsOnHomeTimeline(new ListTweetsOnHomeTimelineOptions()); foreach (var tweet in tweets) { Console.WriteLine("{0} says '{1}'", tweet.User.ScreenName, tweet.Text); } } catch (Exception e) { Console.WriteLine("Exception encountered: {0}", e.Message); } Console.WriteLine("Press any key to continue..."); while (!Console.KeyAvailable) { } }
public void ShareOnTwitter() { string post = ""; post = update_text.Text; if (post.Length > 140) { post = post.Substring(0, 137) + "…"; } twitter_post = post; if (tokenx == " " && tokensecx == " " || tokenx == null && tokensecx == null) { NavigationService.Navigate(new Uri(string.Format("/TwitterLoginPage.xaml?vpost={0}", post), UriKind.Relative)); } else { ////////////////////////// OAuthCredentials credentials = new OAuthCredentials(); credentials.Type = OAuthType.ProtectedResource; credentials.SignatureMethod = OAuthSignatureMethod.HmacSha1; credentials.ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader; credentials.ConsumerKey = TwitterSettings.ConsumerKey; credentials.ConsumerSecret = TwitterSettings.ConsumerKeySecret; credentials.Token = tokenx; credentials.TokenSecret = tokensecx; credentials.Version = "1.1"; //credentials.ClientUsername = ""; credentials.CallbackUrl = "none"; var service = new TwitterService(TwitterSettings.ConsumerKey, TwitterSettings.ConsumerKeySecret); service.AuthenticateWith(tokenx, tokensecx); SendTweetOptions st = new SendTweetOptions(); st.Status = "post"; service.SendTweet(new SendTweetOptions { Status = post }, CallBackVerifiedResponse1); // ShowProgressIndicator(AppResources.GettingLocationProgressText); /////////////////////////////// } }
public void PostTweet_WithValidCredentials_Succeeds() { // Arrange var controller = new TwitterController(); var token = controller.GetAuthToken(OAuthConsumerKey, OAuthConsumerSecret); var tweet = new SendTweetOptions { Status = "Hacking #HackApply-" + DateTime.Now.Millisecond }; var actual = controller.PostTweet(token, tweet); Assert.IsNotNull(actual); }
public async Task ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages) { Trace.TraceInformation("\n"); Trace.TraceInformation("........ProcessEventsAsync........"); foreach (EventData eventData in messages) { try { string jsonString = Encoding.UTF8.GetString(eventData.GetBytes()); Trace.TraceInformation(string.Format("Message received at '{0}'. Partition: '{1}'", eventData.EnqueuedTimeUtc.ToLocalTime(), this.partitionContext.Lease.PartitionId)); Trace.TraceInformation(string.Format("-->Raw Data: '{0}'", jsonString)); SensorEvent newSensorEvent = this.DeserializeEventData(jsonString); Trace.TraceInformation(string.Format("-->Serialized Data: '{0}', '{1}', '{2}', '{3}'", newSensorEvent.deviceid, newSensorEvent.x, newSensorEvent.y, newSensorEvent.z)); // Issuing alarm to device. string commandParameterNew = "{\"Name\":\"vibrationdetected\",\"Parameters\":{\"deviceid\":\"" + newSensorEvent.deviceid + "\"}}"; Trace.TraceInformation("Issuing alarm to device: '{0}'", newSensorEvent.deviceid); Trace.TraceInformation("New Command Parameter: '{0}'", commandParameterNew); await WorkerRole.iotHubServiceClient.SendAsync(newSensorEvent.deviceid, new Microsoft.Azure.Devices.Message(Encoding.UTF8.GetBytes(commandParameterNew))); // Tweeting here string consumerKey = ConfigurationManager.AppSettings["Twitter.ConsumerKey"]; string consumerSecret = ConfigurationManager.AppSettings["Twitter.ConsumerSecret"]; string accessToken = ConfigurationManager.AppSettings["Twitter.AccessToken"]; string accessSecret = ConfigurationManager.AppSettings["Twitter.AccessSecret"]; // Obtain keys by registering your app on https://dev.twitter.com/apps or https://apps.twitter.com/ var service = new TwitterService(consumerKey, consumerSecret); service.AuthenticateWith(accessToken, accessSecret); SendTweetOptions x = new SendTweetOptions(); x.Status = string.Format("{0} was flipped on {1} UTC, position data: x={2}, y={3}, z={4}", newSensorEvent.deviceid, eventData.EnqueuedTimeUtc.ToString(), newSensorEvent.x, newSensorEvent.y, newSensorEvent.z); service.SendTweet(x); } catch (Exception ex) { Trace.TraceInformation("Error in ProssEventsAsync -- {0}\n", ex.Message); } } await context.CheckpointAsync(); }
public async Task ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages) { Trace.TraceInformation("\n"); Trace.TraceInformation("........ProcessEventsAsync........"); foreach (EventData eventData in messages) { try { string jsonString = Encoding.UTF8.GetString(eventData.GetBytes()); Trace.TraceInformation(string.Format("Message received at '{0}'. Partition: '{1}'", eventData.EnqueuedTimeUtc.ToLocalTime(), this.partitionContext.Lease.PartitionId)); Trace.TraceInformation(string.Format("-->Raw Data: '{0}'", jsonString)); SensorEvent newSensorEvent = this.DeserializeEventData(jsonString); Trace.TraceInformation(string.Format("-->Serialized Data: '{0}', '{1}', '{2}', '{3}', '{4}'", newSensorEvent.timestart, newSensorEvent.dsplalert, newSensorEvent.alerttype, newSensorEvent.message, newSensorEvent.targetalarmdevice)); // Issuing alarm to device. string commandParameterNew = "{\"Name\":\"AlarmThreshold\",\"Parameters\":{\"SensorId\":\"" + newSensorEvent.dsplalert + "\"}}"; Trace.TraceInformation("Issuing alarm to device: '{0}', from sensor: '{1}'", newSensorEvent.targetalarmdevice, newSensorEvent.dsplalert); Trace.TraceInformation("New Command Parameter: '{0}'", commandParameterNew); await WorkerRole.iotHubServiceClient.SendAsync(newSensorEvent.targetalarmdevice, new Microsoft.Azure.Devices.Message(Encoding.UTF8.GetBytes(commandParameterNew))); // Tweeting here string consumerKey = ConfigurationManager.AppSettings["Twitter.ConsumerKey"]; string consumerSecret = ConfigurationManager.AppSettings["Twitter.ConsumerSecret"]; string accessToken = ConfigurationManager.AppSettings["Twitter.AccessToken"]; string accessSecret = ConfigurationManager.AppSettings["Twitter.AccessSecret"]; // Obtain keys by registering your app on https://dev.twitter.com/apps or https://apps.twitter.com/ var service = new TwitterService(consumerKey, consumerSecret); service.AuthenticateWith(accessToken, accessSecret); SendTweetOptions x = new SendTweetOptions(); x.Status = string.Format("Temprature Anomaly detected fom FRDM-K64F! (Auto-generated messsage from Azure Stream Analytics)"); service.SendTweet(x); } catch (Exception ex) { Trace.TraceInformation("Error in ProssEventsAsync -- {0}\n", ex.Message); } } await context.CheckpointAsync(); }
public void ShareOnTwitter() { MainVen.Venue selectedVenue = post_location.SelectedItem as MainVen.Venue; string post = ""; post = "I'm at " + selectedVenue.name; twitter_post = post; if (tokenx == " " && tokensecx == " " || tokenx == null && tokensecx == null) { NavigationService.Navigate(new Uri(string.Format("/TwitterLoginPage.xaml?vpost={0}", post), UriKind.Relative)); } else { ////////////////////////// OAuthCredentials credentials = new OAuthCredentials(); credentials.Type = OAuthType.ProtectedResource; credentials.SignatureMethod = OAuthSignatureMethod.HmacSha1; credentials.ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader; credentials.ConsumerKey = TwitterSettings.ConsumerKey; credentials.ConsumerSecret = TwitterSettings.ConsumerKeySecret; credentials.Token = tokenx; credentials.TokenSecret = tokensecx; credentials.Version = "1.1"; //credentials.ClientUsername = ""; credentials.CallbackUrl = "none"; var service = new TwitterService(TwitterSettings.ConsumerKey, TwitterSettings.ConsumerKeySecret); service.AuthenticateWith(tokenx, tokensecx); SendTweetOptions st = new SendTweetOptions(); st.Status = "post"; service.SendTweet(new SendTweetOptions { Status = post }, CallBackVerifiedResponse1); /////////////////////////////// } }
public HttpResponseMessage PublishTweet(string tweetText) { var service = new TwitterService(_consumerKey, _consumerSecret); service.AuthenticateWith(_token, _tokenSecret); var tweet = new SendTweetOptions { DisplayCoordinates = false, Status = tweetText }; service.SendTweet(tweet); return(new HttpResponseMessage { StatusCode = service.Response.StatusCode, ReasonPhrase = service.Response.StatusDescription }); }