Getting Google API C++ Client to work
Recently, I was given a task to use only C++ and Gmail API to fetch emails, so I decided to go ahead and use the SDK provided by Google. This client api is really dated and if you go onto Google's developer documentation, there is not much information about how to use the sdk.
Getting the sdk to work is really not a walk in the park. There are several problems that I faced when building the library. Firstly, there is not much information on how to use the sdk and luckily there is a calendar sample that demonstrate how to use the api espcially the authentication part of Google which requires the use of OAuth 2.0.
To start using the Google client api library, we first need to create a project, next we have to download the secrets that can be used for the application. When I was doing the task, I was stuck on the OAuth part for quite some time. It turns out, I was using the same OAuth store that the Calendar sample was using and thus I could not authenticate my account.
After I got that to work, I am ready to download some emails from Gmail. I followed the sample given by the calendar sample and tried to use the similar functionality. Initially I tried to use the similar method to download the email, but I got no results. And also, while I was trying to download email, I encountered an issue with undefined symbols. Upon further inspection, I realized that Google api generators for C++ does not generate the proper code for the Gmail api and this result in partial code. Luckily this are easy to fix as the functionality are similar to some of the implemented functionality.
Fixing that, I thought everything is going smoothly and I tried to download some emails. It is here that I ran into some issues with the client giving me some error. Initially I thought it was my code that was giving me issue. This took some time for me to resolve until I came across this issue which lead me to check the code generated by the api generator. It is there that I realized that the function signature is wrong for the gmail service which takes in StringPiece instead of string and this causes the function to not be overridden properly.
Fixing this is also quite trivial, just change the function signatures. If anybody is interested in getting it to work, feel free to get the code here on gitlab.