EDIT: As Google have redesigned the API Console, the details of the steps below have changed - see comments
OK here goes, step by step
- Go to Google Cloud Console and register your project (aka application)
- You need to note the Client ID, and Client Secret
- Go to the OAuth Playground, click the gear icon and choose and enter your own credentials
- You will be reminded that you need to go back to the Cloud COnsole and add the Oauth Playground as a valid callback url. So do that.
- Do Step 1, choosing the spreadsheet scope and click authorize
- Choose your Google account if prompted and grant auth when prompted
- Do Step 2, Click 'Exchange auth code for tokens'
- You will see an input box containing a refresh token
The refresh token is the equivalent of your long lived username/password, so this is what you'll hard code (or store someplace secure your app can retrieve it).
When you need to access Google Spreadsheets, you will call
POST https://accounts.google.com/o/oauth2/token
content-type: application/x-www-form-urlencoded
client_secret=************&grant_type=refresh_token&refresh_token=1%2xxxxxxxxxx&client_id=999999999999.apps.googleusercontent.com
which will return you an access token
{
"access_token": "ya29.yyyyyyyyyyyyyyyyyy",
"token_type": "Bearer",
"expires_in": 3600
}
Put the access token into an http header for whenever you access the spreadsheet API
Authorization: Bearer ya29.yyyyyyyyyyyyyyyyy
And you're done