Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import adal
- import urllib
- import requests
- import urllib2
- ## set variables
- username = 'curtis@tenant.onmicrosoft.com'
- password = 'OFoarry8Oe$'
- authorization_url = 'https://login.windows.net/tenant.onmicrosoft.com' # Authority
- redirect_uri = 'https://login.microsoftonline.com/login.srf'
- client_id = 'dcbf844f-d2c3-42d1-8a7d-0f838f57899a' # Client id
- ## use ADAL to create token response
- token_response = adal.acquire_token_with_username_password(
- authorization_url,
- username,
- password
- )
- ## endpoints discovery
- ## https://api.office.com/discovery/v2.0/me/allServices
- ## create refresh token and save it to use later
- refresh_token = token_response['refreshToken']
- refresh_token_file = open('refresh_token.txt', 'w')
- refresh_token_file.write(refresh_token)
- refresh_token_file.close()
- ## get saved refresh token and use it to get new token response
- refresh_token = open('refresh_token.txt', 'r').read()
- token_response = adal.acquire_token_with_refresh_token(authorization_url, str(refresh_token))
- ## get access_token from token response
- access_token = token_response.get('accessToken')
- headers = {'Authorization':'BEARER ' + str(access_token)}
- print access_token
- ## download file
- file_url = 'https://tenant.sharepoint.com/_api/v1.0/files/root:/myfoldername/myfilename.csv:/content'
- r = requests.get(file_url, headers=headers)
- print r.text
- {"error":"invalid_client","error_description":"Invalid audience Uri 'https://management.core.windows.net/'."}
- https://tenant.sharepoint.com/Shared%20Documents/myfoldername/myfilename.csv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement