Wednesday, 2 July 2014

Accessing Google data, part 2


Back in Novemeber 2012, I blogged about accessing Google data from APEX - and provided some sample code to getting started. You can find this post here:

Over the past little while, I have been (slowly) working on a more modularised API, that can be easily built upon to add support for additional Google services. I have called it PL/GAPI (Google API). It can be found on github:

I hope the wiki on github is straightforward enough to follow in setting this up in your local environment:


I've started with the following services:
  • Drive
  • Calendar

Without going into too much detail (since it's all on the wiki linked earlier), you link to an authorization URL with: 


This tells the system where to return to and P0_SCOPE defines what scope you are requesting authorization for. Current scopes defined:

Once the user accepts, they are returned to the application in the parameters specified in the above redirect (p_return_app, p_return_page) along with the item to store the refresh token in.

Refresh token is a means to be able to get the access token without continually prompting the user for access. All requests require a valid access token to complete successfully. Because the returned refresh token contains the '/' character, it is escaped by APEX. Before storing it, you need to un-escape the string. To do this, I used the function: UTL_I18N.UNESCAPE_REFERENCE. 

Once we have the refresh token, we can easily get the access token with:


Read more about the implementation here:

Then for example, we can add a new folder to our drive:

            p_folder_name       => :P2_NEW_FOLDER_NAME
          , p_access_token      => :GOOGLE_ACCESS_TOKEN);

I've set up a few examples on the wiki, but really, at this stage, the sample application in the samples folder is the best tool to refer to for sample usage


Any feedback, criticisms, suggestions about the implementation are more than welcomed.

note: It's a long way from being complete, but just thought it was time to share.

No comments:

Post a Comment