title: Accessing a Google Drive spreadsheet from Appengine
body: <p>I have an appengine app that needs to access a single, hard-coded spreadsheet on Google Drive.  </p>
  
  <p>Up until now I have been achieving this as follows:</p>
  
  <pre><code>SpreadsheetService service = new SpreadsheetService("myapp");
  service.setUserCredentials("myusername@gmail.com", "myhardcodedpassword");
  </code></pre>
  
  <p>When I tried this today with a new user, I got <code>InvalidCredentialsException</code> even though the username and password were definitely correct.  I got an email in my inbox saying suspicions sign-ins had been prevented, and there seems to be no way to enable them again.</p>
  
  <p>I am also aware that hardcoding passwords in source is bad practice.</p>
  
  <p>However, I have read very widely online for how to enable OAuth/OAuth2 for this, and have ended up wasting hours and hours piecing fragments of information from blogs, stackoverflow answers etc, to no avail.</p>
  
  <p>Ideally the solution would involve an initial process to generate a long-lived access token, which could then be hard-coded in to the app.</p>
  
  <p>I want a definitive list of steps for how to achieve this? </p>