The Google Data API Toolkit is a great resource for extending the Salesforce cloud to connect to Google Data tools including Docs, Spreadsheets and Calendars. One of the first requirements for anyone using the toolkit is to understand the authentication process. Up until now, the authentication mechanism supported in the toolkit was AuthSub Proxies

At a high level AuthSub assumes that your Google Data credentials are the same as your credentials. This works great in many cases, and provides a seamless integration. But what about when this is not the case, or your business case relies on retrieving information from a spreadsheet that you do not want to share with everyone? A good example may be a private quotation formula that you pass in specific data, and return the results. 

The good news is that the Google APIs support another mechanism called Client Login. Client Login allows you to pass username and passwords to Google to perform authentication. Once you get your head around the Google API, the process is very simple, and lends itself well to implementation in Apex. Under the hood it is basically HTTP POSTs with the following code about all you need to get going:
     Http m_http = new Http();
            HttpRequest req = new HttpRequest();
            String content = 'accountType=HOSTED_OR_GOOGLE&Email='+username+'&Passwd='+passwd+'&service='+service;

You will notice a few items that may not be clear at first glance, specifically the service attribute which is a different name each Google Data type (Docs, Spreadsheet, Calendar). These service attributes are included in the Google API pages (an example is Google Spreadsheets here )but to make things a little easier I have updated a number of the core Google Data API toolkit classes available  so all you have to do to leverage Client Login is as easy as this:

DocumentService service = new DocumentService();
service.useClientLogin('', 'itsasecret');
GoogleData docs = service.getDocuments();

So, there is no excuse, it's time to start leveraging the power of all the clouds.

Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS