title: How to Get User Token for Slack API
body: <p>I have a completely script-based python Slack App I want to run, but it needs a User (not a bot) token. I can use legacy tokens fine, but I want to get a token via oauth. I'm having a lot of trouble figuring out how to do this, though! I've added a local redirect to the app and I've tried this code:</p>
  
  <pre><code>def _get_credentials(self):
  
      credential_dir = os.path.join(PATH, '.credentials')
  
      if not os.path.exists(credential_dir):
          os.makedirs(credential_dir)
  
      credential_path = os.path.join(credential_dir,
                                     CREDENTIALS_LOCATION)
  
      store = oauth2client.file.Storage(credential_path)
      credentials = store.get()
  
      if not credentials or credentials.invalid:
  
          clientSecretPath = os.path.join(PATH, CLIENT_SECRET_FILE)
          flow = client.flow_from_clientsecrets(clientSecretPath, SCOPES)
          flow.user_agent = APPLICATION_NAME
  
          #### START PROBLEM ###
  
          credentials = tools.run_flow(flow, store)
  
          #### BREAKS ####
  
          print('Storing credentials to ' + credential_path)
  
      return credentials 
  </code></pre>
  
  <p>All the problems I experience are on the line designated by the hash-tags.</p>
  
  <p>The first is that if the credentials file doesn't exist, instead of creating it, it breaks.</p>
  
  <p>If I create an empty file with the name I want, then the web browser opens and asks the user to authenticate. If they do, they go to a page that says the "authentication process was complete." However, in terminal it shows <code>Authentication has failed: Invalid response: 302</code> and nothing is stored to the credentials file.</p>
  
  <p>In either case, it never hits the line after #### BREAKS ####</p>
  
  <p>What am I doing wrong, or better yet, how do I do this right?</p>