title: Is there a way to reuse Google.Apis.Auth.OAuth2.UserCredential object to authorize SpreadsheetsService?
body: <p>I'm trying to use the Google Drive and Spreadsheets APIs from a C# console app. I'd like to authorize both services using user credentials with a <code>FileDataStore</code> so that I don't have to reauth my app every single time it runs. Below is how I'm authorizing my Drive service object:</p>
  
  <pre><code>var userCredential = GoogleWebAuthorizationBroker.AuthorizeAsync
  (
    new ClientSecrets 
    { 
      ClientId = "[clientID]", 
      ClientSecret = "[clientSecret]" 
    },
    new [] 
    { 
      "https://www.googleapis.com/auth/drive",    
      "https://spreadsheets.google.com/feeds" 
    },
    "[userName]",
    CancellationToken.None,
    new FileDataStore("MyApp.GoogleDrive.Auth.Store")
  ).Result;
  
  var driveService = new DriveService
  (
    new BaseClientService.Initializer
    {
      HttpClientInitializer = userCredential,
      ApplicationName       = "MyApp",
    }
  );
  </code></pre>
  
  <p>For the Spreadsheets service, I'm authorizing as prescribed by <a href="https://developers.google.com/google-apps/spreadsheets/#authorizing_requests_with_oauth_20" rel="nofollow">this guide</a>, but every time I run my app, I have to open a browser to the given auth URL and  manually copy in the access token to get it to work.</p>
  
  <p><strong>Is there a way to auth once, obtain the user credentials as above, and use them with both services? Note, I'm authorizing with both the Drive and the Spreadsheets scope, so I don't think there's a problem with that.</strong></p>
  
  <p>I've tried to make it work like this, but I keep getting 400 Bad Request errors when I attempt to insert rows into my spreadsheet:</p>
  
  <pre><code>var auth = new OAuth2Parameters 
  { 
    ClientId     = "[clientID]",
    ClientSecret = "[clientSecret]",
    RedirectUri  = "[redirectUri]",
    Scope        = "https://www.googleapis.com/auth/drive https://spreadsheets.google.com/feeds" ,
    AccessToken  = userCredential.Token.AccessToken,
    RefreshToken = userCredential.Token.RefreshToken,
    TokenType    = userCredential.Token.TokenType,
  };
  
  var requestFactory = new GOAuth2RequestFactory(null, "MyApp", auth);
  
  var spreadsheetsService = new SpreadsheetsService("MyApp") 
  { 
    Credentials    = new GDataCredentials(userCredential.Token.TokenType + " " + userCredential.Token.AccessToken),
    RequestFactory = requestFactory,
  };
  </code></pre>