title: Printing spreadsheet to PDF then saving file in Drive using OAuth2
body: <pre><code>  function topdf() {
    var foldersave=DriveApp.getFolderById('0Byy1DdsfdfTQRnVlfb05wOV83T00') 
    var d= new Date()
  
    var oauthConfig = UrlFetchApp.addOAuthService("google");
    var scope = "https://docs.google.com/feeds/";
  
    //make OAuth connection
    oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
    oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
    oauthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
    oauthConfig.setConsumerKey("anonymous");
    oauthConfig.setConsumerSecret("anonymous");
  
    //get request
    var request = {
      "method": "GET",
      "oAuthServiceName": "google",
      "oAuthUseToken": "always",
      "muteHttpExceptions": true
    };
  
    var key='1QUj_OyHisdfsdfjwfNu1l-JuI528ev6FNRJv-oljIY'; 
    var fetch='https://docs.google.com/spreadsheets/d/'+key+'/export?format=pdf&amp;size=A4&amp;portrait=false'
  
    var name = "Timestamp  for: "+ d + ".pdf";
    var pdf = UrlFetchApp.fetch(fetch, request);
    pdf = pdf.getBlob().setName(name);
    var file = foldersave.createFile(pdf)
  }
  </code></pre>
  
  <p>I'm looking for a step by step tutorial to convert the above code using OAuth2 . I'm having some problems migrating. I can find bits of code on OAuth2, but don't know how it ties together. The code was really simple before, now it seems to be much more complicated? Or am I missing something simple?</p>
  
  <p>I've tried to replace the OAuth connection section but having trouble. <a href="https://github.com/googlesamples/apps-script-oauth2" rel="nofollow">https://github.com/googlesamples/apps-script-oauth2</a> it seems like the <code>getDriveService</code> should be used somehow?</p>