Skip to content

Commit a1f7639

Browse files
committed
Add readme changes
1 parent a371dda commit a1f7639

File tree

4 files changed

+132
-6
lines changed

4 files changed

+132
-6
lines changed

README.md

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99

1010
## Overview
1111

12+
Microsoft Graph is the gateway to data and intelligence in Microsoft 365. It provides
13+
a unified programmability model that you can use to access the tremendous amount of data
14+
in Microsoft 365, Windows 10, and Enterprise Mobility + Security. This project utilizes python
15+
to help users interact with and manage data on Microsoft Graph API.
16+
1217
## Setup
1318

14-
**Setup - Requirements Install:***
19+
**Setup - Requirements Install:**
1520

1621
For this particular project, you only need to install the dependencies, to use the project. The dependencies
1722
are listed in the `requirements.txt` file and can be installed by running the following command:
@@ -52,23 +57,76 @@ you can use the library wherever you want.
5257
To **install** the library, run the following command from the terminal.
5358

5459
```console
55-
pip install federal-register
60+
pip install
5661
```
5762

5863
**Setup - PyPi Upgrade:**
5964

6065
To **upgrade** the library, run the following command from the terminal.
6166

6267
```console
63-
pip install --upgrade federal-register
68+
pip install --upgrade
6469
```
6570

6671
## Usage
6772

68-
Here is a simple example of using the `place_holder` library.
73+
Here is a simple example of using the `ms_graph` library.
6974

7075
```python
71-
76+
from pprint import pprint
77+
from ms_graph.client import MicrosoftGraphClient
78+
from configparser import ConfigParser
79+
80+
scopes = [
81+
'Calendars.ReadWrite',
82+
'Files.ReadWrite.All',
83+
'User.ReadWrite.All',
84+
'Notes.ReadWrite.All',
85+
'Directory.ReadWrite.All',
86+
'User.Read.All',
87+
'Directory.Read.All',
88+
'Directory.ReadWrite.All',
89+
'offline_access',
90+
'openid',
91+
'profile'
92+
]
93+
94+
# Initialize the Parser.
95+
config = ConfigParser()
96+
97+
# Read the file.
98+
config.read('config/config.ini')
99+
100+
# Get the specified credentials.
101+
client_id = config.get('graph_api', 'client_id')
102+
client_secret = config.get('graph_api', 'client_secret')
103+
redirect_uri = config.get('graph_api', 'redirect_uri')
104+
105+
# Initialize the Client.
106+
graph_client = MicrosoftGraphClient(
107+
client_id=client_id,
108+
client_secret=client_secret,
109+
redirect_uri=redirect_uri,
110+
scope=scopes,
111+
credentials='config/ms_graph_state.jsonc'
112+
)
113+
114+
# Login to the Client.
115+
graph_client.login()
116+
117+
118+
# Grab the User Services.
119+
user_services = graph_client.users()
120+
121+
# List the Users.
122+
pprint(user_services.list_users())
123+
124+
125+
# Grab the Drive Services.
126+
drive_services = graph_client.drives()
127+
128+
# List the Root Drive.
129+
pprint(drive_services.get_root_drive())
72130
```
73131

74132
## Support These Projects

samples/configs/write_config_video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
config.set('graph_api', 'redirect_uri', '')
1313

1414
# Write the file.
15-
with open(file='configs/config_video.ini', mode='w+') as f:
15+
with open(file='samples/configs/config_video.ini', mode='w+') as f:
1616
config.write(f)

samples/images/azure_directory.jpg

64.2 KB
Loading

samples/setting_up_an_app.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Using the Microsoft Graph API
2+
3+
## Overview
4+
5+
Microsoft Graph is the gateway to data and intelligence in Microsoft 365. It provides
6+
a unified programmability model that you can use to access the tremendous amount of data
7+
in Microsoft 365, Windows 10, and Enterprise Mobility + Security. Use the wealth of data
8+
n Microsoft Graph to build apps for organizations and consumers that interact with millions
9+
of users.
10+
11+
## Register an App
12+
13+
### Step 1: Go to your Azure Portal
14+
15+
For step 1 you'll need to go to your [Azure Portal](https://portal.azure.com/) and login.
16+
17+
### Step 2: Go to the Azure Active Directory Service
18+
19+
Once you've logged into Azure you'll need to register a new application so you can access
20+
the Microsoft Graph API. To register a new application go to your **Azure Active Directory**
21+
and once there go down to **App Registrations** a new window will pop up.
22+
23+
### Step 3: Register a New App
24+
25+
Select **New registration**. On the Register an application page, set the values as follows.
26+
27+
- Set Name to **Python Graph Tutorial**.
28+
- Set **Supported account** types to Accounts in any organizational directory and personal Microsoft accounts.
29+
- Under **Redirect URI**, set the first drop-down to Web and set the value to <http://localhost:8000/callback>.
30+
31+
### Step 4: Grab your Client ID
32+
33+
Select **Register**. On the *Python Graph Tutorial* page, copy the value of the **Application (client) ID** and
34+
save it, you will need it in the next step.
35+
36+
### Step 5: Create a Client Secret
37+
38+
Select **Certificates & secrets** under Manage. Select the **New client secret** button. Enter a value in
39+
Description and select one of the options for Expires and select Add. **MAKE SURE TO COPY THE CLIENT SECRET**
40+
**BEFORE YOU LEAVE THE PAGE OR ELSE YOU WILL NOT BE ABLE TO GRAB IT AGAIN AND WILL NEED TO CREATE A NEW ONE.**
41+
42+
### Step 6: Save the Content to a Config File (Optional)
43+
44+
If you want you can save the content to a config file using python and then when you need to grab your credentials
45+
you can simply read the config file into your script. Some alternative options is using an Azure Key Vault or storing
46+
the credentials in environment variables. To save the content in a config file use the sample file in the [configs folder](https://github.com/areed1192/ms-graph-python-client/tree/master/samples/configs)
47+
that is found in the samples folder.
48+
49+
Make sure to fill out the values in the file:
50+
51+
```python
52+
from configparser import ConfigParser
53+
54+
# Initialize the Parser.
55+
config = ConfigParser()
56+
57+
# Add the Section.
58+
config.add_section('graph_api')
59+
60+
# Set the Values.
61+
config.set('graph_api', 'client_id', '')
62+
config.set('graph_api', 'client_secret', '')
63+
config.set('graph_api', 'redirect_uri', '')
64+
65+
# Write the file.
66+
with open(file='samples/configs/config_video.ini', mode='w+') as f:
67+
config.write(f)
68+
```

0 commit comments

Comments
 (0)