public string Tweet(ITwitterAuthorizer auth, string status) { using (var twitterCtx = new TwitterContext(auth)) { var tweet = twitterCtx.UpdateStatus(status); return(tweet.StatusID); } }
public string Tweet(ITwitterAuthorizer auth, string status) { using (var twitterCtx = new TwitterContext(auth)) { var tweet = twitterCtx.UpdateStatus(status); return tweet.StatusID; } }
/// <summary> /// supports testing /// </summary> /// <param name="oAuthTwitter">IOAuthTwitter Mock</param> public TwitterExecute(ITwitterAuthorizer authorizedClient) { if (authorizedClient == null) { throw new ArgumentNullException("authorizedClient"); } this.AuthorizedClient = authorizedClient; this.AuthorizedClient.UserAgent = m_linqToTwitterVersion; }
private void OAuthWebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { try { if (OAuthWebBrowser.Url.Query.ToLowerInvariant().Contains("oauth_verifier")) { auth.CompleteAuthorization(OAuthWebBrowser.Url); } if (auth.IsAuthorized) { Authorizer = auth; // This is how you access credentials after authorization. // The oauthToken and oauthTokenSecret do not expire. // You can use the userID to associate the credentials with the user. // You can save credentials any way you want - database, isolated storage, etc. - it's up to you. // You can retrieve and load all 4 credentials on subsequent queries to avoid the need to re-authorize. // When you've loaded all 4 credentials, LINQ to Twitter will let you make queries without re-authorizing. // //var credentials = pinAuth.CredentialStore; //string oauthToken = credentials.OAuthToken; //string oauthTokenSecret = credentials.OAuthTokenSecret; //string screenName = credentials.ScreenName; //ulong userID = credentials.UserID; // try { ShareSettings.Default.TwitterOAuthToken = auth.Credentials.OAuthToken; ShareSettings.Default.TwitterAccessToken = auth.Credentials.AccessToken; ShareSettings.Default.Save(); } catch (Exception ex) { Log.Error(ex); } Action closeAction = () => Close(); if (InvokeRequired) { Invoke(closeAction); } else { closeAction(); } } } catch (Exception ex) { Log.Error(ex); } }
public AccountsDialogViewModel(IColumnDefinitionList columnList, ITwitterContextList contextList, ITwitterAuthorizer authorizer) { ContextList = contextList; ColumnList = columnList; Authorizer = authorizer; AddedAccounts = new ObservableCollection <AccountEntry>(ContextList.Contexts.Select(c => new AccountEntry(c))); foreach (var acc in AddedAccounts) { acc.ConfirmationChanged += Acc_ConfirmationChanged; } }
private void StartButton_Click(object sender, RoutedEventArgs e) { ITwitterAuthorizer auth = SharedState.Authorizer; if (auth == null || !auth.IsAuthorized) { NavigationService.Navigate(new Uri("/OAuth.xaml", UriKind.Relative)); } else { int count = 0; var twitterCtx = new TwitterContext(auth); var collection = new ObservableCollection <StreamItem>(); StreamListBox.ItemsSource = collection; (from strm in twitterCtx.UserStream where strm.Type == UserStreamType.User select strm) .StreamingCallback(strm => Dispatcher.BeginInvoke(() => { if (strm.Status == TwitterErrorStatus.RequestProcessingException) { WebException wex = strm.Error as WebException; if (wex != null && wex.Status == WebExceptionStatus.ConnectFailure) { MessageBox.Show(wex.Message + " You might want to reconnect."); } MessageBox.Show(strm.Error.ToString()); return; } string message = string.IsNullOrWhiteSpace(strm.Content) ? "Keep-Alive" : strm.Content; collection.Add( new StreamItem { Message = DateTime.Now.ToString() + ": " + message }); if (count++ >= 25) { strm.CloseStream(); MessageBox.Show("Stream for this demo is closing..."); } })) .SingleOrDefault(); } }
private void OAuthWebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { try { if (OAuthWebBrowser.Url.Query.ToLowerInvariant().Contains("oauth_verifier")) { auth.CompleteAuthorization(OAuthWebBrowser.Url); } if (auth.IsAuthorized) { Authorizer = auth; // This is how you access credentials after authorization. // The oauthToken and oauthTokenSecret do not expire. // You can use the userID to associate the credentials with the user. // You can save credentials any way you want - database, isolated storage, etc. - it's up to you. // You can retrieve and load all 4 credentials on subsequent queries to avoid the need to re-authorize. // When you've loaded all 4 credentials, LINQ to Twitter will let you make queries without re-authorizing. // //var credentials = pinAuth.CredentialStore; //string oauthToken = credentials.OAuthToken; //string oauthTokenSecret = credentials.OAuthTokenSecret; //string screenName = credentials.ScreenName; //ulong userID = credentials.UserID; // try { ShareSettings.Default.TwitterOAuthToken = auth.Credentials.OAuthToken; ShareSettings.Default.TwitterAccessToken = auth.Credentials.AccessToken; ShareSettings.Default.Save(); } catch (Exception ex) { Log.Error(ex); } Action closeAction = () => Close(); if (InvokeRequired) Invoke(closeAction); else closeAction(); } } catch (Exception ex) { Log.Error(ex); } }
private void TweetButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(TweetTextBox.Text)) { MessageBox.Show("Please enter text to tweet."); } ITwitterAuthorizer auth = SharedState.Authorizer; if (auth == null || !auth.IsAuthorized) { NavigationService.Navigate(new Uri("/OAuth.xaml", UriKind.Relative)); } else { var twitterCtx = new TwitterContext(auth); twitterCtx.UpdateStatus(TweetTextBox.Text, updateResp => Dispatcher.BeginInvoke(() => { switch (updateResp.Status) { case TwitterErrorStatus.Success: Status tweet = updateResp.State; User user = tweet.User; UserIdentifier id = user.Identifier; MessageBox.Show( "User: "******", Posted Status: " + tweet.Text, "Update Successfully Posted.", MessageBoxButton.OK); break; case TwitterErrorStatus.TwitterApiError: case TwitterErrorStatus.RequestProcessingException: MessageBox.Show( updateResp.Exception.ToString(), updateResp.Message, MessageBoxButton.OK); break; } })); } }
private void btnAuthorize_Click(object sender, RoutedEventArgs e) { e.Handled = true; ITwitterAuthorizer auth = PerformAuthorization(); if (auth == null) { return; } var ctx = new TwitterContext(auth); Application.Current.Properties["context"] = ctx; Application.Current.Properties["userName"] = ctx.UserName; userName.Text = "@" + ctx.UserName; stackWelcome.Visibility = System.Windows.Visibility.Visible; btnAuthorize.IsEnabled = false; }
static ITwitterAuthorizer ChooseAuthenticationStrategy() { Console.WriteLine("Authentication Strategy:\n\n"); Console.WriteLine(" 1 - Pin (default)"); Console.WriteLine(" 2 - Single User"); Console.WriteLine(" 3 - XAuth"); Console.WriteLine(" 4 - Application-Only"); Console.Write("\nPlease choose (1, 2, 3, or 4): "); ConsoleKeyInfo input = Console.ReadKey(); Console.WriteLine(""); ITwitterAuthorizer auth = null; switch (input.Key) { case ConsoleKey.D1: auth = DoPinOAuth(); break; case ConsoleKey.D2: auth = DoSingleUserAuth(); break; case ConsoleKey.D3: auth = DoXAuth(); break; case ConsoleKey.D4: auth = DoApplicationOnly(); break; default: auth = DoPinOAuth(); break; } return(auth); }
private void SearchButton_Click(object sender, RoutedEventArgs e) { ITwitterAuthorizer auth = SharedState.Authorizer; if (auth == null || !auth.IsAuthorized) { NavigationService.Navigate(new Uri("/OAuth.xaml", UriKind.Relative)); } else { var twitterCtx = new TwitterContext(auth, SharpGIS.WebRequestCreator.GZip); (from search in twitterCtx.Search where search.Type == SearchType.Search && search.Query == QueryTextBox.Text select search) .MaterializedAsyncCallback(asyncResponse => Dispatcher.BeginInvoke(() => { if (asyncResponse.Status != TwitterErrorStatus.Success) { MessageBox.Show("Error during query: " + asyncResponse.Exception.Message); return; } Search search = asyncResponse.State.SingleOrDefault(); var tweets = (from status in search.Statuses select new Tweet { UserName = status.User.Identifier.ScreenName, Message = status.Text, ImageSource = status.User.ProfileImageUrl }) .ToList(); SearchListBox.ItemsSource = tweets; })); } }
private void btnAuthorize_Click(object sender, RoutedEventArgs e) { e.Handled = true; chkAcceptToShare.IsEnabled = false; ITwitterAuthorizer auth = PerformAuthorization(); if (auth == null) { return; } var ctx = new TwitterContext(auth); Application.Current.Properties["context"] = ctx; Application.Current.Properties["userName"] = ctx.UserName; Application.Current.Properties["sessionGUID"] = Guid.NewGuid().ToString(); userName.Text = "@" + ctx.UserName; stackWelcome.Visibility = System.Windows.Visibility.Visible; btnAuthorize.IsEnabled = false; WebUtils.ReportNewUser(ctx.UserName, (string)Application.Current.Properties["sessionGUID"]); }
public TwitterContextTests() { TestCulture.SetCulture(); auth = new Mock <ITwitterAuthorizer>().Object; }
private void DoSingleUserAuth() { // configure the OAuth object this.auth = new SingleUserAuthorizer { Credentials = new InMemoryCredentials { ConsumerKey = this.twitterConsumerKey, ConsumerSecret = this.twitterConsumerSecret, OAuthToken = this.twitterOAuthToken, AccessToken = this.twitterAccessToken } }; try { // do not call authorize // auth.Authorize(); this.twtCtx = new TwitterContext(this.auth); } catch (TwitterQueryException ex) { System.Console.WriteLine("\nCannot login with those credentials: {0}", ex.Message); throw; } }
static void Main() { ITwitterAuthorizer auth = ChooseAuthenticationStrategy(); if (auth == null) { return; } try { using (var twitterCtx = new TwitterContext(auth)) { //Log twitterCtx.Log = Console.Out; // // Each Run section below will execute at least one demo // from the specified area of the Twitter API. // Uncomment and navigate to code to see the example. // // LINQ to Twitter documentation "Making API Calls" is here: // http://linqtotwitter.codeplex.com/wikipage?title=Making%20API%20Calls&referringTitle=Documentation // // Each section supports the Twitter API, as documented here: // http://dev.twitter.com/doc // if (DoThis("demo account")) { AccountDemos.Run(twitterCtx); } //BlocksDemos.Run(twitterCtx); //DirectMessageDemos.Run(twitterCtx); //FavoritesDemos.Run(twitterCtx); //FriendshipDemos.Run(twitterCtx); //GeoDemos.Run(twitterCtx); //HelpDemos.Run(twitterCtx); //ListDemos.Run(twitterCtx); //RawDemos.Run(twitterCtx); //ReportSpamDemos.Run(twitterCtx); //RelatedResultsDemos.Run(twitterCtx); //SavedSearchDemos.Run(twitterCtx); //SearchDemos.Run(twitterCtx); //SocialGraphDemos.Run(twitterCtx); //StatusDemos.Run(twitterCtx); //StreamingDemo.Run(twitterCtx); if (DoThis("demo trend")) { TrendsDemos.Run(twitterCtx); } UserDemos.Run(twitterCtx); //OAuthDemos.Run(twitterCtx); //TwitterContextDemos.Run(twitterCtx); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Console.WriteLine("Press any key to end this demo."); Console.ReadKey(); }
public Connector() { _oAuthorizer = DoApplicationOnly(); _context = new TwitterContext(_oAuthorizer); }
/// <summary> /// Initializes a new instance of the <see cref="TwitterContext"/> class. /// </summary> /// <param name="authorization">The authorization.</param> public TwitterContext(ITwitterAuthorizer authorization) #if SILVERLIGHT : this(authorization, (IWebRequestCreate)null) #else : this(new TwitterExecute(authorization))
public TwitterContextUrlTests() { TestCulture.SetCulture(); auth = new Mock<ITwitterAuthorizer>().Object; }
public LttService(ITwitterStatusFeed statusFeed, ITwitterAuthorizer authorizer) { _statusFeed = statusFeed; _authorizer = authorizer; }