This Library makes it easy to use OAuth. It is also flexible in that you can specify any google service names and an optional scope. This is only required if your API is not yet in our list. 

Project Key: MM5uQxqjwkMiuJW2zE50SgUF7jOZt2NQ8


Installing the OAuth Library

1. In the script editor, click on Resources > Manage librairies...

2.  In the Included Libraries window, insert the project key into the Find a Library textbox and click on the Select button.

Project Key: MM5uQxqjwkMiuJW2zE50SgUF7jOZt2NQ8

3. Select the Stable version from the drop down list.  

       *Note that the Identifier is how you call the library. 
Clicking the blue "Title" link will bring up the documentation window. 

4. In your code type: Oauthapp. 
    You will see the available choices in the autocomplete box. 

Using the Library

The .getAuth method takes an apiName as its argument from the list below.

Google service names:

Service apiName
 Analytics Data API  analytics
 Blogger  blogger
 Book Search Data API  booksearch
 Calendar  calendar
 Contacts  contacts
 Content API for Shopping  shopping
 Documents List Data API  docs   
 Fusion Tables    fusion
 Google+  gplus
 PicasaWeb  picasaweb
 Spreadsheets  spreadsheets
 Sites  sites
 Youtube  youtube
*Your API not listed? Use the optUserScope arg 

In this example you are going to call on the getAuth(apiName) method. You will then be asked to grant access to your app. After granting access you will be able to get your G+ posts. 

To run this Google+ example you will need to head over to the API Console and get a key. More help on getting your key.

Connect to Google+

function gPlusMe(){

  var options = Oauthapp.getAuth('gplus');
  var API_KEY = '<YOUR_API_KEY>';  
  var result = UrlFetchApp.fetch("https://www.googleapis.com/plus/v1/people/me?alt=json&key="+API_KEY, options);
  var plusObject  = Utilities.jsonParse(result.getContentText());
  Logger.log(plusObject.displayName); //returns your Name

Reference Documentation

Method:  getAuth(apiName, optUserScope)

 apiName String      a Google API service name
 optUserScpoe   String *OPTIONAL* use to define a custom scope