title: Creating and storing Google credentials in token.pickle from auth code
body: <p>I am writing a program which uses a local <code>token.pickle</code> file to access the user's Google Calendar.</p>
  <p>It runs on a server and what I want is for the user to be able to login through a web interface and then the server creates and stores the token.pickle file, created from the auth code the page sends back to the server.</p>
  <p>Where I am at is that my Python backend receives the authorization code but I don't know how to create the token.pickle file from that... I know I need to exchange the code for the user's credentials though and I probably need to use the following snippets:</p>
  <pre><code>with open('token.pickle', 'wb') as token:
          pickle.dump(creds, token)
  </code></pre>
  <p>and</p>
  <pre><code># Set path to the Web application client_secret_*.json file you downloaded from the
  # Google API Console: https://console.developers.google.com/apis/credentials
  CLIENT_SECRET_FILE = '/path/to/client_secret.json'
  
  # Exchange auth code for access token, refresh token, and ID token
  credentials = client.credentials_from_clientsecrets_and_code(
      CLIENT_SECRET_FILE,
      ['https://www.googleapis.com/auth/drive.appdata', 'profile', 'email'],
      auth_code)
  </code></pre>
  <p>Thanks, I would greatly appreciate any help.</p>
  <p><strong>EDIT:</strong></p>
  <p>Okay, so I would like to save some sort of way of getting the credentials or the credentials themselves from the access token, so I can access them from:</p>
  <p><code>service = build('calendar', 'v3', credentials=creds)</code></p>
  <p>Can anybody clarify or give me a way to do this please?</p>