This project has moved and is read-only. For the latest updates, please go here.

Firewall issues

Oct 18, 2012 at 10:38 PM

Is anyone else having issues with using LinqToTwitter API [Search feature] behind a firewall?

My application works outside of the firewall.

Oct 19, 2012 at 2:10 AM


All URLs default to https (port 443), which is best practice. You could manually change URLs via constructor or properties of TwitterContext and OAuthAuthorizer derived type, but I don't recommend it.


Oct 19, 2012 at 7:50 PM
Edited Oct 19, 2012 at 11:01 PM

Thanks Joe,

Let me clarify my question. I'm unable to make my application work when running it in VWD, from behind the firewall. It seems to choke on trying to retrieve results of the search query. This has started happening recently.

I can run/debug from VWD outside the firewall however and the query returns just fine.

Here's the error message my application throws -

[InvalidOperationException: Sequence contains no elements]
   LinqToTwitter.TwitterQueryProvider.Execute(Expression expression) +405
   System.Linq.Queryable.Single(IQueryable`1 source) +265

Any idea how I can work around this?

EDIT: I tried installing version 2.1 and using oAuth, but still not getting back the statuses. I'm thinking I need to put in a callback url perhaps? How would I do this as I'm using VWD development environment?

Sorry if I'm missing something really basic.

Oct 20, 2012 at 1:56 AM

The cause of the exception is that you aren't receiving any items in the response. Therefore, Single will throw an exception. To avoid the exception, you can use SingleOrDefault and then check the results for null before trying to use it.

While that removes the cause of the exception, it won't help fix your other problem, related to your firewall. I mentioned port 443 in case it's blocked by the firewall, but that still sounds unlikely because how would you ever use SSL - I mention it anyway in case it might help.

Just to let you know, there shouldn't be any inherent difficulty with a firewall, as long as it allows normal Web traffic and communication with Twitter. I'm not sure what to do, except share ideas until something starts working. Here are a couple ideas:

1. Download the LINQ to Twitter source code and run one of the demos that are similar to what you're trying to do, both inside and outside the firewall. The LinqToTwitterDemo project has working code and we'll know more after running that.

2. If that doesn't work, download Fiddler2 and watch the traffic request and response for the API you're having trouble with. The responses are in JSON and you can find a free JSON formatter on-line that will make it more readable if the response is large. Look at response headers to see if they provide information. You might have to configure decryption in Fiddler2 to see the results, but there's help on the download site.  This is a great tool that I use all the time, so you might want to get it anyway to help debug future problems, using this as an excellent way to learn how to use it.

Before posting anything, make sure you sanitize your OAuth headers so you don't accidentally share your credentials.


Oct 22, 2012 at 9:08 PM
Edited Oct 22, 2012 at 9:44 PM

Thanks Joe,

The problem within the firewall persists. I'm unable to properly configure Fiddler to work with the proxy server.

From outside the firewall, I'm seeing couple other issues though... One, is an issue with paging.

I was getting an error "Page parameter not recognized" [not exact wording], so in the first pass through the iteration in my code, I commented out 

//search.Page == 1

That helped and I was able to retrieve results for my 1st search query. (yay! about 5-10 tweets matching my query for location specified)

(I have different query strings that I pass with every iteration through my list of query strings.)

The second issue happens at this point, so that on "second" pass through the loop, I'm getting this error - 401 Could not authenticate you

I'm using the exact method for oAUTH that you have prescribed in your demos, so I know I'm doing that right, and I authenticate once, and my iterative code is within the scope of this authenticated TwitterContext. I also tried re-authenticating with every pass through the loop but that didn't seem to help.

This happens every time I run my application. It chokes on the second pass. It could not be rate limit, as I only get 5-10 tweets with my first query

Seem like I may be missing something .. Thanks!

Oct 23, 2012 at 12:58 AM

Here's a blog post I did on working with timelines - Search will be similar because it has SinceID and MaxID. BTW, Page was recently deprecated:

Here's the LINQ to Twitter FAQ, which provides tips on how to work with 401 errors:


Oct 24, 2012 at 5:12 AM
Edited Oct 24, 2012 at 8:21 AM

Joe, Thanks for the blog post.

I figured it was something in my query string [single quotes] that was causing the issue. It's strange that twitter responded with "Could not authenticate you"!!