Wednesday, May 2, 2012

Building a Twitter Client In InfoPath

Item is currently unrated. Press SHIFT+ENTER to rate this item.1 star selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+ESCAPE to leave rating submit mode.2 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.3 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.4 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.5 stars selected. Press SHIFT+ENTER to submit. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.
Categories:InfoPath; Twitter; Site Manager/Power User; MOSS; WSS; 2007; 2010

InfoPath 2010 introduced the ability to get external data from a “REST Web Service.”’ REST (REpresentational State Transfer) services became the darling of Web 2.0 a few year s back when Facebook exposed their API as a ‘RESTful’ service. Every other major site has since followed suit and we now have the ability to deeply integrate our projects with the social experience.
The exact definition of a RESTful system has become a source of contention among geeks. Proponents of ‘pure’ REST architecture point to Roy Fielding’s 2000 PhD dissertation. They cite things like reuse of HTTP verbs, meaningful headers, stateless protocols and identifiable resources. This group would be shocked at the InfoPath implementation. InfoPath has no idea what a header is, can only make GET requests, and you can return data in any format you want, as long as it’s XML.
I however, ask myself one simple question when deciding if I can call a system RESTful. ‘Can I hook that up to Twitter?’
We begin with a new blank form, and add a REST Web Service from the Data tab.
Compared to the SOAP equivalent, the REST Web Service settings are very simplistic. Simply add a URL to receive data from, and save the data connection. In this example we will point InfoPath to, and give it a name.
This URL can be broken into three distinct parts
  • – the base URL that hosts the Search API
  • search.rss - this specifies that we want our response formatted as an RSS feed. ATOM and JSON are also available, but ATOM doesn’t have all the fields we need, and InfoPath doesn’t understand JSON.
  • ?q=infopath – here we specify what we want to search for in our query sting using the q parameter. We’ve chosen to search for “twitter” by default.
After saving the connection you’ll have a new Secondary Data Source.
Drag the item repeating group onto your form as a Repeating Section with Controls, and after expanding all the fields, preview your form.
If you receive an error when you preview the form, go under File > Advanced Form Options > Security and Trust and set the form to Full Trust mode. This certainly isn’t a best practice, but it get’s around InfoPaths reluctance to make cross domain calls in the simplest way possible.
This is neat, but what about if you want to search for something other than ‘twitter’? Users of SOAP web services are familiar with setting a query field in a data source, but REST Web Services are handled a little differently. Start by adding a field at the top of your page named keyword, and put a button under that. Click on the button and a new Control Tools contextual menu will appear. Click on Rules to open the buttons rules pane.
Under Add you have a new action for 2010, “Change REST URL”.
In this action, you will use the concat() function to build a formula that combines the text “” and the value entered in the keyword field. Be careful when entering the URL, if you don’t enter the URL to the exact same RESTful resource, your data source will break. This is one of the drawbacks of the REST Web Service in 2010.
Add a second action to your rule to query the Twitter data source after modifying the URL. Without this the form won’t be refreshed with new data after you’ve clicked your search button.
Preview your form and try searching with a new value in the keyword field. I’ve made the Title field wider and multi-line to make it easier to read as well.
You now have a functioning Twitter search in InfoPath! However, there is one problem, it’s pretty ugly. To add a little extra visual appeal we’ll use another 2010 feature, the image control. Right click on the image_link field and change the control type to Picture.
I’ve also moved around some fields to make the tweet more readable, and but a border at the top and bottom of the repeating section to differentiate between tweets easier.
Preview your form and you have a sharp looking, enterprise-ready Twitter search.


InfoPath 2010 brought with it the ability to make calls to RESTful web services. However, ’HTTP’ web service would be a better name for this feature as InfoPath doesn’t support most features that make a REST architecture so appealing. Nevertheless, it does open the door to some interesting opportunities. In this article you’ve seen how to use the Twitter search API to pull data from twitter, then design a form to query the service and display tweets using features like the image control.
Knowing how to use REST web services in InfoPath enables us to use all kinds of data sources. InfoPath developers are no longer restricted to web services with a valid WSDL files. We can now request any valid XML (and potentially even HTML) and parse the response. Sources with rich, URL based identifiers like SharePoint list oData feeds are among the data sources that are opened up thanks to RESTful web servies.
If you would like to see the full form, please visit

No comments:

Post a Comment