This describes how to use Goa, as described in Oauth2 for Apps Script in a few lines of code (which you should read first for background).
The library, cGoa, is available under this project key, or on github. All the tests described for this topic are also available on github.
When using service accounts Goa knows how to get the developers console credentials from a downloaded file. In most of the examples I show setting up the once off credentials by explicitly setting the client id and secret. I then advise you delete that function since after running it once since its not a good idea to keep your credentials in your code, especially if you load that code to github or otherwise make it public.
It is possible to download web credentials from the developers console too, as below.
You can now set your once off package up using this downloaded file. That way you don't have to expose any credentials in your code, and if you do accidentally leave the file id there, it's anyway protected by being on your private drive. Here's two ways of doing the same thing. The first reads it from file, and in the second the credentials are set explicitly. Using this first method I dont have to care too much about leaving the file id in the script (although I've obfuscated it in any case), since only I can access it.
Of course this only works for Google APIS. Other APIS still need to set the credentials explicitly. If any others have the capability of downloading a credential file, let me know and I'll add them.
For more like this, see OAuth2 for Apps Script in a few lines of code Why not join our forum, follow the blog or follow me on twitter to ensure you get updates when they are available.
Learning Apps Script, (and transitioning from VBA) are covered comprehensively in my my book, Going Gas - from VBA to Apps script, All formats are available from O'Reilly, Amazon and all good bookshops. You can also read a preview on O'Reilly
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > OAuth2 for Apps Script in a few lines of code >