private WebAuthorizer auth; private TwitterContext twitterCtx; protected void Page_Load(object sender, EventArgs e) { IOAuthCredentials credentials = new SessionStateCredentials(); if (credentials.ConsumerKey == null || credentials.ConsumerSecret == null) { credentials.ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"]; credentials.ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"]; } auth = new WebAuthorizer { Credentials = credentials, PerformRedirect = authUrl => Response.Redirect(authUrl) }; if (!Page.IsPostBack && Request.QueryString["oauth_token"] != null) { auth.CompleteAuthorization(Request.Url); } if (string.IsNullOrWhiteSpace(credentials.ConsumerKey) || string.IsNullOrWhiteSpace(credentials.ConsumerSecret)) { //Do nothing } else if (auth.IsAuthorized) { //Do nothing } else { auth.BeginAuthorization(Request.Url); if (!auth.IsAuthorized) { Uri specialUri = new Uri(Request.Url.ToString()); auth.BeginAuthorization(specialUri); } } if (auth.IsAuthorized) { twitterCtx = new TwitterContext(auth); #region Search Text var searchResult = (from srch in twitterCtx.Search where srch.Type == SearchType.Search && srch.Query == "Brian Adams" select srch) .SingleOrDefault(); gvTweetView.DataSource = searchResult.Statuses; gvTweetView.DataBind(); #endregion #region UserInfo var users = (from user in twitterCtx.User where user.Type == UserType.Lookup && user.ScreenName == "prosarfraz" select user); string strHtml = string.Empty; foreach (User objUser in users) { strHtml += ""; strHtml += " Screen Name "; strHtml += "" + objUser.ScreenName + ""; strHtml += " Favorites Count "; strHtml += "" + objUser.FavoritesCount + ""; strHtml += " Followers "; strHtml += "" + objUser.FollowersCount + ""; strHtml += " Description "; strHtml += "" + objUser.Description + ""; strHtml += ""; } ulsrc.InnerHtml = "" + strHtml + "
"; #endregion } }