Skip to content

Commit a0287c6

Browse files
authored
Merge pull request #67 from microsoftgraph/sdk-update
SDK Update
2 parents d281902 + 46e70a4 commit a0287c6

File tree

5 files changed

+45
-33
lines changed

5 files changed

+45
-33
lines changed

app-auth/graphapponlytutorial/main.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# <ProgramSnippet>
55
import asyncio
66
import configparser
7+
from msgraph.generated.models.o_data_errors.o_data_error import ODataError
78
from graph import Graph
89

910
async def main():
@@ -30,16 +31,21 @@ async def main():
3031
except ValueError:
3132
choice = -1
3233

33-
if choice == 0:
34-
print('Goodbye...')
35-
elif choice == 1:
36-
await display_access_token(graph)
37-
elif choice == 2:
38-
await list_users(graph)
39-
elif choice == 3:
40-
await make_graph_call(graph)
41-
else:
42-
print('Invalid choice!\n')
34+
try:
35+
if choice == 0:
36+
print('Goodbye...')
37+
elif choice == 1:
38+
await display_access_token(graph)
39+
elif choice == 2:
40+
await list_users(graph)
41+
elif choice == 3:
42+
await make_graph_call(graph)
43+
else:
44+
print('Invalid choice!\n')
45+
except ODataError as odata_error:
46+
print('Error:')
47+
if odata_error.error:
48+
print(odata_error.error.code, odata_error.error.message)
4349
# </ProgramSnippet>
4450

4551
# <DisplayAccessTokenSnippet>
@@ -53,7 +59,7 @@ async def list_users(graph: Graph):
5359
users_page = await graph.get_users()
5460

5561
# Output each users's details
56-
if users_page is not None and users_page.value is not None:
62+
if users_page and users_page.value:
5763
for user in users_page.value:
5864
print('User:', user.display_name)
5965
print(' ID:', user.id)

app-auth/graphapponlytutorial/pylintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,5 +576,5 @@ preferred-modules=
576576

577577
# Exceptions that will emit a warning when being caught. Defaults to
578578
# "BaseException, Exception".
579-
overgeneral-exceptions=BaseException,
580-
Exception
579+
overgeneral-exceptions=builtins.BaseException,
580+
builtins.Exception

user-auth/graphtutorial/graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def get_inbox(self):
7272
query_parameters= query_params
7373
)
7474

75-
messages = await self.user_client.me.mail_folders_by_id('inbox').messages.get(
75+
messages = await self.user_client.me.mail_folders.by_mail_folder_id('inbox').messages.get(
7676
request_configuration=request_config)
7777
return messages
7878
# </GetInboxSnippet>

user-auth/graphtutorial/main.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# <ProgramSnippet>
55
import asyncio
66
import configparser
7+
from msgraph.generated.models.o_data_errors.o_data_error import ODataError
78
from graph import Graph
89

910
async def main():
@@ -33,24 +34,29 @@ async def main():
3334
except ValueError:
3435
choice = -1
3536

36-
if choice == 0:
37-
print('Goodbye...')
38-
elif choice == 1:
39-
await display_access_token(graph)
40-
elif choice == 2:
41-
await list_inbox(graph)
42-
elif choice == 3:
43-
await send_mail(graph)
44-
elif choice == 4:
45-
await make_graph_call(graph)
46-
else:
47-
print('Invalid choice!\n')
37+
try:
38+
if choice == 0:
39+
print('Goodbye...')
40+
elif choice == 1:
41+
await display_access_token(graph)
42+
elif choice == 2:
43+
await list_inbox(graph)
44+
elif choice == 3:
45+
await send_mail(graph)
46+
elif choice == 4:
47+
await make_graph_call(graph)
48+
else:
49+
print('Invalid choice!\n')
50+
except ODataError as odata_error:
51+
print('Error:')
52+
if odata_error.error:
53+
print(odata_error.error.code, odata_error.error.message)
4854
# </ProgramSnippet>
4955

5056
# <GreetUserSnippet>
5157
async def greet_user(graph: Graph):
5258
user = await graph.get_user()
53-
if user is not None:
59+
if user:
5460
print('Hello,', user.display_name)
5561
# For Work/school accounts, email is in mail property
5662
# Personal accounts, email is in userPrincipalName
@@ -66,13 +72,13 @@ async def display_access_token(graph: Graph):
6672
# <ListInboxSnippet>
6773
async def list_inbox(graph: Graph):
6874
message_page = await graph.get_inbox()
69-
if message_page is not None and message_page.value is not None:
75+
if message_page and message_page.value:
7076
# Output each message's details
7177
for message in message_page.value:
7278
print('Message:', message.subject)
7379
if (
74-
message.from_ is not None and
75-
message.from_.email_address is not None
80+
message.from_ and
81+
message.from_.email_address
7682
):
7783
print(' From:', message.from_.email_address.name or 'NONE')
7884
else:
@@ -90,7 +96,7 @@ async def send_mail(graph: Graph):
9096
# Send mail to the signed-in user
9197
# Get the user for their email address
9298
user = await graph.get_user()
93-
if user is not None:
99+
if user:
94100
user_email = user.mail or user.user_principal_name
95101

96102
await graph.send_mail('Testing Microsoft Graph', 'Hello world!', user_email or '')

user-auth/graphtutorial/pylintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,5 +576,5 @@ preferred-modules=
576576

577577
# Exceptions that will emit a warning when being caught. Defaults to
578578
# "BaseException, Exception".
579-
overgeneral-exceptions=BaseException,
580-
Exception
579+
overgeneral-exceptions=builtins.BaseException,
580+
builtins.Exception

0 commit comments

Comments
 (0)