You're probably better off just using this: the python library used there seems to handle errors better https://gist.github.com/buckleytom/0ecfbbb546913c7d9814
However, if you really want to:
This script uses RCurl and RJSONIO to download data from Google's API to get the travel time and distance between latitudes and longitudes by mode, based on some data in a csv