@@ -46,37 +46,31 @@ There are **two approaches** available to perform API queries:
46
46
47
47
1 . ` ClientContext class ` - where you target SharePoint resources such as ` Web ` , ` ListItem ` and etc (recommended)
48
48
49
+ ``` python
50
+ from office365.sharepoint.client_context import ClientContext
49
51
50
- ```
51
-
52
- from office365.sharepoint.client_context import ClientContext
53
-
54
- ctx = ClientContext(site_url).with_credentials(UserCredential(username, password))
55
- web = ctx.web
56
- ctx.load(web)
57
- ctx.execute_query()
58
- print "Web title: {0}".format(web.properties['Title'])
59
- ```
60
- or alternatively via method chaining (a.k.a Fluent Interface):
61
-
52
+ ctx = ClientContext(site_url).with_credentials(UserCredential(username, password))
53
+ web = ctx.web
54
+ ctx.load(web)
55
+ ctx.execute_query()
56
+ print " Web title: {0} " .format(web.properties[' Title' ])
62
57
```
58
+ or alternatively via method chaining (a.k.a Fluent Interface):
63
59
64
- from office365.sharepoint.client_context import ClientContext
65
-
66
- ctx = ClientContext(site_url).with_credentials(UserCredential(username, password))
67
- web = ctx.web.load().execute_query()
68
- print "Web title: {0}".format(web.properties['Title'])
69
- ```
60
+ ``` python
61
+ from office365.sharepoint.client_context import ClientContext
70
62
63
+ ctx = ClientContext(site_url).with_credentials(UserCredential(username, password))
64
+ web = ctx.web.load().execute_query()
65
+ print " Web title: {0} " .format(web.properties[' Title' ])
66
+ ```
71
67
72
68
73
69
2 . ` RequestOptions class ` - where you construct REST queries (and no model is involved)
74
70
75
71
The example demonstrates how to read ` Web ` properties:
76
72
77
-
78
-
79
- ```
73
+ ``` python
80
74
import json
81
75
from office365.runtime.auth.UserCredential import UserCredential
82
76
from office365.runtime.http.request_options import RequestOptions
@@ -88,7 +82,6 @@ response = ctx.execute_request_direct(request)
88
82
json = json.loads(response.content)
89
83
web_title = json[' d' ][' Title' ]
90
84
print (" Web title: {0} " .format(web_title))
91
-
92
85
```
93
86
94
87
@@ -119,7 +112,7 @@ The example demonstrates how to send an email via [Microsoft Graph endpoint](htt
119
112
120
113
> Note: access token is getting acquired via [ Client Credential flow] ( https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow )
121
114
122
- ```
115
+ ``` python
123
116
def get_token (auth_ctx ):
124
117
token = auth_ctx.acquire_token_with_client_credentials(
125
118
" https://graph.microsoft.com" ,
@@ -175,7 +168,7 @@ which corresponds to [`list available drives` endpoint](https://docs.microsoft.c
175
168
176
169
> Note: access token is getting acquired via [ Client Credential flow] ( https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow )
177
170
178
- ```
171
+ ``` python
179
172
def get_token (auth_ctx ):
180
173
""" Acquire token via client credential flow (ADAL Python library is utilized)"""
181
174
token = auth_ctx.acquire_token_with_client_credentials(
@@ -197,7 +190,7 @@ for drive in drives:
197
190
198
191
##### Example: download the contents of a DriveItem(folder facet)
199
192
200
- ```
193
+ ``` python
201
194
# retrieve drive properties (source)
202
195
drive = client.users[user_id_or_principal_name].drive
203
196
client.load(drive)
@@ -210,7 +203,7 @@ with tempfile.TemporaryDirectory() as path:
210
203
211
204
where
212
205
213
- ```
206
+ ``` python
214
207
def download_files (remote_folder , local_path ):
215
208
drive_items = remote_folder.children
216
209
client.load(drive_items)
@@ -241,18 +234,16 @@ library is utilized to authenticate users to Active Directory (AD) and obtain to
241
234
The example demonstrates how create a new team under a group
242
235
which corresponds to [ ` Create team ` endpoint] ( https://docs.microsoft.com/en-us/graph/api/team-put-teams?view=graph-rest-1.0&tabs=http )
243
236
244
- ```
245
-
237
+ ``` python
246
238
tenant_name = " contoso.onmicrosoft.com"
247
239
client = GraphClient(tenant_name, get_token)
248
240
new_team = client.groups[group_id].add_team()
249
241
client.execute_query()
250
-
251
242
```
252
243
253
244
where
254
245
255
- ```
246
+ ``` python
256
247
def get_token (auth_ctx ):
257
248
""" Acquire token via client credential flow (ADAL Python library is utilized)
258
249
:type auth_ctx: adal.AuthenticationContext
0 commit comments