0

Having seen this post : Streaming Tweets with LinqToTwitter

I have this WebForms code:

 protected void uxBtnGetTweets_Click(object sender, EventArgs e)
    {
        DataManager dman = new DataManager();
        UsersOpenAuthData data = dman.GetUserTokens(uxTxtScreenName.Text);
        if (data == null)
        {
            throw new Exception("User Not Authorized, No Tokens On File");
        }
        credentials = new SessionStateCredentials()
        {
            ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
            ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"],
            OAuthToken = data.OAuthToken,
            AccessToken = data.AccessToken
        };
        auth = new WebAuthorizer
        {
            Credentials = credentials,
            PerformRedirect = authUrl => Response.Redirect(authUrl),
        };
        TwitterContext twitterCtx = new TwitterContext(auth);
        int count = 0;
        int max = 5;
        lines = new List<string>();

        var s = (from strm in twitterCtx.UserStream
                 where strm.Type == UserStreamType.User
                 select strm).StreamingCallback(strm =>
                      {
                          if (strm.Status == TwitterErrorStatus.RequestProcessingException)
                          {
                              WebException wex = strm.Error as WebException;
                              if (wex != null && wex.Status == WebExceptionStatus.ConnectFailure)
                              {
                                  throw (wex);
                              }
                              throw new Exception(strm.Error.ToString());
                          }
                          //Here both "lines" and statusJson are populated
                          lines.Add(strm.Content);
                          JsonData statusJson = JsonMapper.ToObject(strm.Content);
                          if (++count >= max)
                          {
                              strm.CloseStream();
                          }
                      }).SingleOrDefault();

             //Here lc == 0
             int lc = lines.Count;
    }

While the steam is active the "lines" list is being populated as is the JsonData object however when the stream closes the lines IList is empty.

All I can think of is scoping problem of some kind but beyond that I am stuck as to how to how to gather data from the steam loop - must we persist it to SQL or session while in the loop?

Any suggestions greatly appreciated!

Community
  • 1
  • 1
Serexx
  • 1,232
  • 1
  • 15
  • 32

1 Answers1

0

answered here : LinqToTwitter Stream Handling Scope

Serexx
  • 1,232
  • 1
  • 15
  • 32