title: Authentication OneDrive API Python
body: <p>Using code sample from GitHub that is specifically for setting up authentication for Python access to OneDrive API (I'm beginning to think this source is outdated), I've failed to make it past the part where you paste code provided by Microsoft after executing program..</p>
  
  <p>Python code:</p>
  
  <pre><code>import onedrivesdk
  
  redirect_uri = 'https://login.microsoftonline.com/common/oauth2/nativeclient'
  client_secret = '*this code omitted*'
  client_id='*this code omitted*'
  api_base_url='https://api.onedrive.com/v1.0/'
  scopes=['onedrive.readwrite']
  
  http_provider = onedrivesdk.HttpProvider()
  auth_provider = onedrivesdk.AuthProvider(
      http_provider=http_provider,
      client_id=client_id,
      scopes=scopes)
  
  client = onedrivesdk.OneDriveClient(api_base_url, auth_provider, http_provider)
  auth_url = client.auth_provider.get_auth_url(redirect_uri)
  # Ask for the code
  print('Paste this URL into your browser, approve the app\'s access.')
  print('Copy everything in the address bar after "code=", and paste it below.')
  print(auth_url)
  code = raw_input('Paste code here: ')
  
  client.auth_provider.authenticate(code, redirect_uri, client_secret)
  </code></pre>
  
  <p>After executing code and pasting url in browser, a popup shows up, where I verify that I want to give my app access to API.. I hit "Ok."</p>
  
  <p>I am then presented with code in URL taskbar. I copy and paste code into program..</p>
  
  <p>Then the error I get is:</p>
  
  <pre><code>    raise Exception(str(message["error"]))
  
  Exception: invalid_request
  </code></pre>
  
  <p>Link to GitHub source used: <a href="https://github.com/OneDrive/onedrive-sdk-python" rel="nofollow noreferrer">https://github.com/OneDrive/onedrive-sdk-python</a></p>
  
  <p>Note: I had to omit scopes such as the first two in this list:</p>
  
  <pre><code>scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite']
  </code></pre>
  
  <p>because they apparently don't exist (according to error code provided by Microsoft after pasting URL into taskbar)</p>
  
  <p>Is there a better source for setting up authentication for a Python program to communicate with OneDrive API?</p>
  
  <p>I am a relatively new Python user, your patience is appreciated.</p>