Making Fitbit API client with scribe-java for OAuth 2.0

So, recently Fitbit has upgraded its API’s OAuth standard to OAuth2.0, however, their docs does not strictly follow the standard of OAuth2.0.

For example, to get the access token, they require a basic authorization in header of the request and the value is the Base64 encoded string of the concatenation of your client id and secret separated by a colon (clientId:clientSecret). This is a bit redundant, IMO, as in the body parameters, you already need to send your client Id.

When I first found out that they use OAuth2.0, I could not wait to try scribe-java as it is a great library for OAuth2.0 client. However, as Fitbit’s one does not really follow exactly the standard, so it’s a bit of hacky to use scribe-java.

Nevertheless, it’s still quite simple to get the job done (thanks to the excellent work of scribe-java). I have made a simple demo in my Github’s repository. You can just copy two classes: FitbitApi20 and Fitbit20ServiceImpl and then the setup will be super smooth to do:

final OAuth20Service service = new ServiceBuilder()
                .scope("activity%20profile") // replace with desired scope
                .callback("")  //your callback URL to store and handle the authorization code sent by Fitbit

Quite easy, isnt?


The PRACTICAL guide for Latex beginners (part 1)

It all started three months ago at the very first week of my Master when I saw my friend Serge who was about to write his report in Latex. I personally had experience with LaTex before when writing my paper but well, it was surely beautiful and fascinating yet somewhat still very complicated for me. ” It might be very time-consuming and inconvenient if I write all my reports in LaTex” said myself at that time.

Yes, it was!! It was very inconvenient, it was very time-consuming and it was actually sometimes tempting to just come back to write everything in MsWord.

But only AT FIRST! For my case, first three or four reports were quite annoying as I needed to google every time I wanted to insert a new symbol or just draw an image or even change the headline etc.  Fortunately I was patient and adventurous enough to stay with LaTex and now I never regret switching to LaTex.

However, what I noticed during those time is that there is not much PRACTICAL guides for those complete LaTex beginners even though there are some tutorials or even many books but from my experience, they are not very suitable and attractive for the new users. Thus, this blog (part 1 and part 2) aims to be an ‘instant noodle’ for those novices who want to jump into LaTex and use it right away rather than reading hundreds introductory pages with so much strange terminologies.

So, fasten your seat-belt and start the trip to Latex world!

What is LaTex?

 It is just another way of inputting text, image and other information to a document. Your traditional way may be MsWord-like way, where you type all the sentences while inserting special symbols or mathematical equations through a graphical user interface (GUI). Specifically, this way is  actually command-line user interface so when you switch from MsWord to LaTex, it feels similar to move to Linux after using Window where you are doing everything with comfortable yet limited GUI. How limited it is you wonder? Just remember how tedious and time-consuming writing your Physics lab’s reports during freshmen year were? Totally not productive and smart at all!!!!

What are the advantages of LaTex? (just say a few)

  • It looks much more beautiful and professional than MsWord documents. Just look at one’s CV written in LaTex and you will see why.
  • Convenient and time-saving to input mathematical equations and Greek letters.
  • Really easy to format your page.
  • If you insert an image and later the content of that image changes, LaTex will automatically change. No manual work needed here.
  • Significantly reduce the time and effort to produce a formal document.
  • Nearly 100% of scientific papers are written by LaTex, so I urge you engineering students, who are close to write your bachelor/Msc/Phd thesis or academic paper or just course work’s weekly report to get used to LaTex since it would be much easier for your life from now on.

Why is it difficult at first?

Remember how difficult it is the first time you have used MsWord? Everything is so hard at first because it is NEW and it takes time to get used to something. It can also be annoying as you need to figure out every basical things like how to insert a picture, how to draw a table , etc. But do not give up because LaTex is actually quite easy and powerful.

Hmm, but maybe I should say this at the front. Practice makes perfect. The only short-cut to fast forward this settling duration is to PRACTICE and PRACTICE more and more, with your own report and papers.


It’s time. Enough words. Let’s start to play around with LaTex! You are advised to follow all the steps behind to see how it works.


Actually, LaTex is not the name of a software to produce documents (like MsWord) but it is only a way so you need to install a software to run LaTex. For this, I would recommend TeXstudio for its balance between simple design and great functionality. You can download and install it from here:

Then just click on the file you have downloaded and follow the instruction. An other option (which is getting more and more popular) if you do not want to install anything is to use some online LaTex editors such as ShareLaTex or WriteLatex. It is up to your preference to choose the one that fits you.

Hello World program

Let’s try some writing in LaTex. Open your TexStudio program and create a new file (Ctrl+N) then copy and paste this paragraph:

\documentclass[a4paper, 11pt]{article}

Hello World! I am a new Latex user!

Press F1 (which is the short-cut for building the document in TexStudio) and see the result. Congratulations! You have created your first LaTex document!!

Basic structure of a Latex document

As you can see from the piece of code  above, there is only a sentence in line 5 (highlighted) actually appearing in the built document. Other parts are only for declaration i.e letting LaTex know what kinds of setting you want. The first line says that you want a document of A4-sized paper with font size of 11pt and the style is like the pre-defined article style in LaTex. There are other built-in styles in LaTex such as book (for real book) or letter (for writing letters).

The next thing you need to do is to declare which package  you want to use in line 2.  Here I simply use package english since I want to write in English. For more complicated purpose you may need to include more packages (talk about it later).

Finally, the actual content of the document will be enclosed in \begin{document}  and \end{document}, so everything you write outside of this should be considered invalid.

Too easy? Let’s make something more advanced!

Ok, this time, copy and paste this piece of code and again, press F1 and see the miracle happens:

\documentclass[a4paper, 11pt]{article}

\lhead{Test LaTex document}
\cfoot{\thepage\ }

Hello World! I am a new Latex user!

\textbf{Exponential example:}
e^{0} = 1 \\
e^{1} = e


Now do you see the difference compared to the Hello world example? Now we have the headline and footnote as well as various new features (equation, boldface…).  To do this, we need to add the new package fancyhdr, which is for making the headline and footnote then we actually use the page style fancy (line 4) then we just need to specify the actual text we want to put on the left headline (lhead), central headline (chead) or center footnote (cfoot) and so on. Note that we can put \today and LaTex will automatically know to put the date of today into the right headline and similarly \thepage means that the current page of the document. Told you, everything is ready in LaTex and you just need to call it.

In addition, we also try to make a sentence bold by using \textbf{} command. Also, for typing exponential notation, just use ^ then follow by the text you want to put on the superscript (enclosed by {}). You do not even need to number the equation by yourself.  It stays automatically and beautifully at the center. Super easy huh?

Enough for today maybe?

So up to now, we have tried pretty complicated LaTex documents (and it is not gonna be much more complicated than this) so that you can have a glance on what LaTex is and how it works. Part 2 of this blog will cover some vital components of a formal document (image, equations, page layout etc.) and I promise it is going to be very easy and practical so that you can start to use it on your next report immediately.