Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit 2673f1c

Browse files
committed
README updates
Add a sample that doesn't use GetAuthCodeServer. Change double quotes to single quotes and remove stray tabs.
1 parent 090b811 commit 2673f1c

File tree

1 file changed

+43
-18
lines changed

1 file changed

+43
-18
lines changed

README.md

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,42 @@ Next, include the SDK in your Python project by adding:
1717

1818
To interact with the OneDrive API, your app must authenticate. You can use the following code sample to do so.
1919

20+
```python
21+
import onedrivesdk
22+
23+
redirect_uri = 'http://localhost:8080/'
24+
client_secret = 'your_client_secret'
25+
client_id='your_client_id'
26+
api_base_url='https://api.onedrive.com/v1.0/'
27+
scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite']
28+
29+
http_provider = onedrivesdk.HttpProvider()
30+
auth_provider = onedrivesdk.AuthProvider(
31+
http_provider=http_provider,
32+
client_id=client_id,
33+
scopes=scopes)
34+
35+
client = onedrivesdk.OneDriveClient(api_base_url, auth_provider, http_provider)
36+
auth_url = client.auth_provider.get_auth_url(redirect_uri)
37+
# Ask for the code
38+
print('Paste this URL into your browser, approve the app\'s access.')
39+
print('Copy everything in the address bar after "code=", and paste it below.')
40+
print(auth_url)
41+
code = input('Paste code here: ')
42+
43+
client.auth_provider.authenticate(code, redirect_uri, client_secret)
44+
```
45+
46+
2047
```python
2148
import onedrivesdk
2249
from onedrivesdk.helpers import GetAuthCodeServer
2350

24-
redirect_uri = "http://localhost:8080/"
25-
client_secret = "your_app_secret"
51+
redirect_uri = 'http://localhost:8080/'
52+
client_secret = 'your_app_secret'
2653

27-
client = onedrivesdk.get_default_client(client_id='your_client_id',
28-
scopes=['wl.signin',
29-
'wl.offline_access',
30-
'onedrive.readwrite'])
54+
client = onedrivesdk.get_default_client(
55+
client_id='your_client_id',
3156

3257
auth_url = client.auth_provider.get_auth_url(redirect_uri)
3358

@@ -48,27 +73,27 @@ can begin making calls using the SDK.
4873
### Upload an Item
4974

5075
```python
51-
returned_item = client.item(drive="me", id="root").children["newfile.txt"].upload("./path_to_file.txt")
76+
returned_item = client.item(drive='me', id='root').children['newfile.txt'].upload('./path_to_file.txt')
5277
```
5378

5479
### Download an Item
5580

5681
```python
57-
root_folder = client.item(drive="me", id="root").children.get()
82+
root_folder = client.item(drive='me', id='root').children.get()
5883
id_of_file = root_folder[0].id
5984

60-
client.item(drive="me", id=id_of_file).download("./path_to_download_to.txt")
85+
client.item(drive='me', id=id_of_file).download('./path_to_download_to.txt')
6186
```
6287

6388
### Add a folder
6489

6590
```python
6691
f = onedrivesdk.Folder()
6792
i = onedrivesdk.Item()
68-
i.name = "New Folder"
93+
i.name = 'New Folder'
6994
i.folder = f
7095

71-
returned_item = client.item(drive="me", id="root").children.add(i)
96+
returned_item = client.item(drive='me', id='root').children.add(i)
7297
```
7398

7499
### Copy an Item
@@ -77,9 +102,9 @@ returned_item = client.item(drive="me", id="root").children.add(i)
77102
from onedrivesdk.item_reference import ItemReference
78103

79104
ref = ItemReference()
80-
ref.id = "yourparent!id" #path also supported
105+
ref.id = 'yourparent!id' #path also supported
81106

82-
copy_operation = client.item(drive="me", id="youritemtocopy!id").copy(name="new copied name", parent_reference=ref).post()
107+
copy_operation = client.item(drive='me', id='youritemtocopy!id').copy(name='new copied name', parent_reference=ref).post()
83108

84109
#copy_operation.item will return None until the copy has completed.
85110
#If you would like to block until the operation has been completed
@@ -92,17 +117,17 @@ copy_operation.poll_until_complete()
92117

93118
```python
94119
renamed_item = onedrivesdk.Item()
95-
renamed_item.name = "NewItemName"
96-
renamed_item.id = "youritemtorename!id"
120+
renamed_item.name = 'NewItemName'
121+
renamed_item.id = 'youritemtorename!id'
97122

98-
new_item = client.item(drive="me", id=renamed_item.id).update(renamed_item)
123+
new_item = client.item(drive='me', id=renamed_item.id).update(renamed_item)
99124
```
100125

101126
### Paging through a collection
102127

103128
```python
104129
#get the top three elements of root, leaving the next page for more elements
105-
collection = client.item(drive="me", id="root").children.request(top=3).get()
130+
collection = client.item(drive='me', id='root').children.request(top=3).get()
106131

107132
#get the first item in the collection
108133
item = collection[0]
@@ -122,7 +147,7 @@ import asyncio
122147

123148
@asyncio.coroutine
124149
def run_gets(client):
125-
coroutines = [client.drive("me").request().get_async() for i in range(3)]
150+
coroutines = [client.drive('me').request().get_async() for i in range(3)]
126151
for future in asyncio.as_completed(coroutines):
127152
drive = yield from future
128153
print(drive.id)

0 commit comments

Comments
 (0)