Error while querying Twitter

Jul 21, 2011 at 3:02 PM

Hi, I got an error more and more often : "Error while querying Twitter".

 

I think it is the API which is not responding, but I just want to be sure.

Is it really for this reason or not ?

 

I can't work maybe 1 hour a day because of that error.

 

Thanks a lot

Coordinator
Jul 21, 2011 at 3:13 PM

Hi,

Here are a few things you can do:

1. Debug your application and look at the exception.  You might need to look at the InnerException or Response property (on TwitterQueryException) for more info.  This might indicate what the problem could be.

2. Find a similar example in the downloadable source code, LinqToTwitterDemo project to see if it has the same problem.

3. Write a small sample application that reproduces the same error.

4. Open Fiddler or Firebug and look at the response from Twitter.

5. If those options don't help you solve the problem, you can post the sample app, stack trace, and Fiddler response here.

Joe

Jul 21, 2011 at 3:31 PM

Hi Joe, thanks for your response.

 

So, the debugger throw the error : "The exception TwitterQueryException was unhandled by user code.  Error while querying Twitter"

I tried with a LinqToTwitterDemo project and I didn't get the same problem (so it may not be cause of Twitter but my code).

And about Firebug, I don't got anything. :(

 

So this is my code : 

var tweets =
                    from tweet in twitterCtx.Status
                    where tweet.Type == (auth.IsAuthorized ? StatusType.Friends : StatusType.Public)
                    && tweet.Count == 50
                    && tweet.Page == 1
                    select tweet;

                try
                {

                    TwitterListView.DataSource = tweets;
                    TwitterListView.DataBind();
                }
                catch (TwitterQueryException ex)
                {
                    retweeteurs.Text = ex.Message.ToString();
                }

I just try to get all tweets and show them in a ListView. And the error occurs on the Databind.

Do you  got any idea ?

Thanks,
Jeff

 

Jul 21, 2011 at 3:33 PM

And the weirdest part of this problem, is that it occurs just sometimes, but most of time it works.

I really don't know why

Coordinator
Jul 21, 2011 at 3:46 PM

Got a stack trace?

Jul 21, 2011 at 3:53 PM

à LinqToTwitter.TwitterQueryProvider.Execute[TResult](Expression expression) dans C:\Projects\LinqToTwitter\LinqToTwitterAg\LinqToTwitter\TwitterQueryProvider.cs:ligne 116 à LinqToTwitter.TwitterQueryable`1.System.Collections.IEnumerable.GetEnumerator() dans C:\Projects\LinqToTwitter\LinqToTwitterAg\LinqToTwitter\TwitterQueryable.cs:ligne 108 à System.Web.UI.WebControls.ListViewPagedDataSource.GetEnumerator() à System.Web.UI.WebControls.ListView.CreateItemsWithoutGroups(ListViewPagedDataSource dataSource, Boolean dataBinding, InsertItemPosition insertPosition, ArrayList keyArray) à System.Web.UI.WebControls.ListView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) à System.Web.UI.WebControls.ListView.PerformDataBinding(IEnumerable data) à System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) à System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) à System.Web.UI.WebControls.DataBoundControl.PerformSelect() à System.Web.UI.WebControls.ListView.PerformSelect() à System.Web.UI.WebControls.BaseDataBoundControl.DataBind() à LinQ2Tweet._Default.Page_Load(Object sender, EventArgs e) dans C:\Users\Jeff\Documents\Visual Studio 2010\Projects\LinQ2Tweet\LinQ2Tweet\Default.aspx.cs:ligne 74

Coordinator
Jul 21, 2011 at 4:19 PM

A couple ideas:

1. Move the auth.IsAuthorized logic out of the query where you can see it's value before the query occurs.  This might tell you whether the problem only occurs during public or friend queries.

2. Materialize the query before assigning it to datasource. 

3. Catch the exception when the query materializes.  Then drill down into the Exception/InnerException object/s and look at the Response property of the TwitterQueryException, which holds the message from Twitter.

4.  You're interested in finding the Response from Twitter and maybe even the HTTP error.

Joe

Jul 21, 2011 at 4:30 PM

When I materialze the query, I got the smae error than during databinding --> Error while querying Twitter.

So got it on the Stacktrace : 


à LinqToTwitter.TwitterQueryProvider.Execute[TResult](Expression expression) dans C:\Projects\LinqToTwitter\LinqToTwitterAg\LinqToTwitter\TwitterQueryProvider.cs:ligne 116 à LinqToTwitter.TwitterQueryable`1.GetEnumerator() dans C:\Projects\LinqToTwitter\LinqToTwitterAg\LinqToTwitter\TwitterQueryable.cs:ligne 99 à System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) à System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) à LinQ2Tweet._Default.Page_Load(Object sender, EventArgs e) dans C:\Users\Jeff\Documents\Visual Studio 2010\Projects\LinQ2Tweet\LinQ2Tweet\Default.aspx.cs:ligne 62

Jul 21, 2011 at 4:30 PM

And Thanks a lot to help me, this error really block me to do my work :)

Sep 10, 2011 at 1:14 PM

I had the error also allot. The point that you said you can't work like 1 hour a day because of this is because of the rate limit. You can check the docu out here: https://dev.twitter.com/docs/rate-limiting 

You can make 150 calls to the api each hour. If you use oauth you can make 350 call to the api.