Archive for the ‘Development’ Category

Shrinking and FatSecret API

Thursday, May 13th, 2010

One of the goals for Shrinking from the beginning was to offer a food and exercise calorie calculator. We wanted to not only make it easy to track your weight loss measurements and weight loss goals, but also provide tools to actually help you achieve success. We thought at first this was going to be a big challenge with several weeks of development time, trial and error, managing profiles and calorie data. We decided to move forward and begin the research and development to create this new tool.

Our first task was to see if there was any type of food nutrition fact resources out on the internet that we could tap into for data. We found a handful of databases with raw data for calories, fat, protein, and carbs, but we were not very happy with how some of the search features worked and search results of the data. It looked like we were going to have more development time that we initially thought. We continued looking for resources that provided full API access to data and search features. We came across the FatSecret Platform and quickly realized we had found exactly what we needed to offer this food and exercise calorie calculator.

FatSecret Platform not only offered the food and exercise calorie calculator, but did it with a very easy to use API. The search feature of adding food and exercise to your daily totals was very fast and efficient. It also returned search results in an order that was easy to use and kept with the simple interface Shrinking has. Shrinking quickly interfaced with FatSecret to create a handy three tab interface for Food Diary, Exercise Diary, and a Calendar. Each FatSecret profile is linked to your own individual Shrinking account, so you can track your personal food calorie intake and calories used during exercise. The calendar lets you see your calories eaten and burned on a daily basis by month.

The FatSecret JavaScript API combined with the PHP REST API wrapper class of FatSecret allowed for a very easy integration! Following are the details of how we implemented this new feature.

We first off had to figure out a way to get existing users’ profiles to work with the FatSecret API and simultaneouly work with new users. We start off by having a user accept the Terms of Conditions, which is a link to the ToC on the FatSecret Platform website. Once they accept and continue, we use that time to store the fact they did agree to the ToC, but also gave us a chance to create the profile on FatSecret. This gave us the perfect situation to call FatSecret->ProfileCreate and pass in the user_id of the Shrinking user, existing or new.

The FatSecret ProfileCreate returns a token and secret key that we store locally in the Shrinking tables for that user. When a user visits the Food Diary tab of their account in Shrinking, we make a call to the FatSecret->ProfileRequestScriptSessionKey passing in the saved token and secret key of the logged in user. The ProfileRequestScriptSessionKey returns a session_key that we then pass into the HTML view of the Food Diary. That session_key is used as a variable when we make the call to the FatSecret JavaScript. By passing in our Shrinking FatSecret API key, along with the generated session_key to the Javascript, we can populate a canvas with the FatSecret returned interface, and then we can style it using CSS to match the Shrinking interface.

Shrinking food and exercise calorie calculator powered by FatSecret Platform