1- # Getting started with the OneDrive SDK for Python
1+ ** # ** Getting started with the OneDrive SDK for Python
22
33------------------------------------------------------------------------
44[ ![ Build status] ( https://ci.appveyor.com/api/projects/status/x1cjahp817w6r455?svg=true )] ( https://ci.appveyor.com/project/OneDrive/vroom-client-python )
@@ -15,6 +15,8 @@ Next, include the SDK in your Python project by adding:
1515
1616## Authentication
1717
18+ ### OneDrive
19+
1820To interact with the OneDrive API, your app must authenticate. You can use the following code sample to do so.
1921
2022``` python
@@ -43,6 +45,9 @@ code = input('Paste code here: ')
4345client.auth_provider.authenticate(code, redirect_uri, client_secret)
4446```
4547
48+ The above code requires copy-pasting into your browser and back into your console. If you want to remove some of
49+ that manual work, you can use the helper class ` GetAuthCodeServer ` . That helper class spins up a webserver, so
50+ this method cannot be used on all environments.
4651
4752``` python
4853import onedrivesdk
@@ -65,6 +70,35 @@ client.auth_provider.authenticate(code, redirect_uri, client_secret)
6570Once your app is authenticated, you should have access to the OneDrive API , and
6671can begin making calls using the SDK .
6772
73+ # ## OneDrive for Business
74+
75+ To interact with the OneDrive API , your app must authenticate for a specific resource. Your
76+ app must first use the Resource Discovery helper to find out which service you can access.
77+ Then, you can build a client to access those resources.
78+
79+ ```python
80+ redirect_uri = ' http://localhost:8080'
81+ client_id = your_client_id
82+ client_secret = your_client_secret
83+ discovery_uri = ' https://api.office.com/discovery/'
84+ auth_server_url = ' https://login.microsoftonline.com/common/oauth2/authorize' ,
85+ auth_token_url = ' https://login.microsoftonline.com/common/oauth2/token'
86+
87+ http = onedrivesdk.HttpProvider()
88+ auth = onedrivesdk.AuthProvider(http,
89+ client_id,
90+ auth_server_url = auth_server_url,
91+ auth_token_url = auth_token_url)
92+ auth_url = auth.get_auth_url(redirect_uri)
93+ code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
94+ auth.authenticate(code, redirect_uri, client_secret, resource = resource)
95+ # If you have access to more than one service, you'll need to decide
96+ # which ServiceInfo to use instead of just using the first one, as below.
97+ service_info = ResourceDiscoveryRequest().get_service_info(auth.access_token)[0 ]
98+ auth.redeem_refresh_token(service_info.service_resource_id)
99+ client = onedrivesdk.OneDriveClient(service_info.service_resource_id + ' /_api/v2.0/' , auth, http)
100+ ```
101+
68102# # Examples
69103
70104** Note:** All examples assume that your app has already been
0 commit comments