Problem with Twitter Widget on Host

Topics: Troubleshooting
Aug 26, 2011 at 5:00 PM

Hi All,

We just released a new Orchard site that we built for the folks at Microsoft Careers: http://microsoftjobsblog.com/. It's running in a shared hosting environment at a company called Aquest hosting.

We used the LatestTwitter module by Maarten Balliauw to include a Twitter widget at the top of the homepage (right under the slider) as well as in the right sidebar on the other pages. It's worked great on our dev machines as well as our test site. But when we deployed to the shared host it stopped working. I wrapped a try/catch around the code that calls Twitter to get the data and had it log the exception. The code that calls twitter is simple, here it is:

WebClient twitterClient = new WebClient();
string address = "http://api.twitter.com/1/statuses/user_timeline.xml?include_entities=1&screen_name=" + part.Username;

try {
    string result = twitterClient.DownloadString(address);
    //Parse the results - removed b/c it's not relevant
}
catch (Exception ex) {
    Logger.Error(ex, "log message ...");
}

And here's the exception:

2011-08-26 11:36:25,128 [11] LatestTwitter.Services.CachedTweetRetrievalService - Error retrieving tweets from Twitter. Attempted to retrieve tweets from:
http://api.twitter.com/1/statuses/user_timeline.xml?include_entities=1&screen_name=MicrosoftJobs
System.Net.WebException: The remote server returned an error: (400) Bad Request.   at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)   at System.Net.WebClient.DownloadString(Uri address)   at System.Net.WebClient.DownloadString(String address)   at LatestTwitter.Services.CachedTweetRetrievalService.RetrieveTweetsFromTwitterFor(TwitterWidgetPart part)

So it's getting a 400 on the web request. The host says they can load that url in a browser on the server and it works. And they say there are no firewall rules that should be blocking it. What's strange is that when we deployed it wasn't working, then it started working for a while, and now it's again not working. Does anyone have any ideas of what could be happening? Any ideas on what I can ask the hosting company to check?

Coordinator
Aug 26, 2011 at 5:31 PM

Might it be that there is an API calls quota ?

Aug 26, 2011 at 5:52 PM
Yes, there is a daily limit for IP Address. Best to use the JavaScript widget, that way it will use the users IP Address or cache with output cache. JS is the better route though.



On 26 Aug 2011, at 17:32, "sebastienros" <notifications@codeplex.com> wrote:

From: sebastienros

Might it be that there is an API calls quota ?

Aug 26, 2011 at 6:46 PM

Doh! Yeah, I think that's exactly the problem. Should have thought of that. Of course we didn't have a problem when testing because we didn't make that many requests (looks like it's limited to 150/hr from an IP). Thanks for helping me see the obvious.  :-)

The LatestTwitter module has caching built-in but I wasn't using it due to a quirk with how it works vs. how we were using it. It caches the results per Twitter user name that you configure a widget for. In our case, I have two different instances of the widget with different settings (i.e. the home page shows 20 tweets but the sidebar only shows 5) but they're both for the same user name. So I couldn't use the cache and just set it to 0.

So what I did was set both widgets to pull 20 tweets, add a cache time of 1 minute, then overrode the template for the sidebar version of the widget to just do a .Take(5) on the list of tweets.

I suppose a better solution would be to modify the module to allow the user to specify the cache key so that it doesn't just always use the Twitter username. Maybe I'll do that ... I've already forked that module about 3 or 4 times and submitted changes to Maarten.  :-)