cereallarceny
cereallarceny

Reputation: 4983

Twitter widget doesn't always populate

I am displaying a Twitter feed from their feed widget on my website. Sometimes the widget likes to not display any information. I figure this is because the API is overloaded. Regardless, is there any known way to display an error message in the event that Twitter can't load my feed? Has anybody else experienced these issues?

Upvotes: 4

Views: 1065

Answers (1)

robocat
robocat

Reputation: 5413

Firstly use a suitable http recording proxy for your OS (Fiddler2 is fantastic if you are on windows), shift F5 the page until you get the fault.

Filter the log for hosts widgets.twimg.com or api.twitter.com... This diagnoses the failure point because:

  1. If the js (or css) request to widgets.twimg.com fails (Look for a 404 or truncated text), then the javascript failed to fetch. Unlikely since files should be static.
  2. If the api.twitter.com request is missing, then the javascript failed to run.
  3. If the api.twitter.com request occurs, but there is a failure in the response (bad response code or response looks whack) then the twitter api is failing to give you the feed.

For detecting 1 in javascript, you can detect the failure to load by using a timeout, and onload check that it loaded (simple check is that window.twttr exists - however not a great test because that gets set at top of javascript, so only confirms that javascript syntax was valid and started running). (Might need onreadystate to detect load for IE?)

<script src="http://widgets.twimg.com/j/2/widget.js" onload="twitterloaded()"></script>

For detecting 2, run page with debugger.

For 3, from a quick look at the code, looks like the code retries requests to the twitter api (you might want to look ath the configuration settings for the api) and it looks like there are api variables to check if everything is running e.g. TWTR.Widget.isLoaded _isRunning and _hasOfficiallyStarted.

Upvotes: 2

Related Questions