This sample is an ongoing project with two main goals: to show how to easily use the Office 365 APIs from Python, and to help me learn Python and Django. A couple of things to keep in mind:
It's assumed that you have Python and Django installed before starting. Windows users should add the Python install directory and Scripts subdirectory to their PATH environment variable.
Download or fork the sample project.
Open your command prompt or shell to the directory where manage.py
is located.
If you can run BAT files, run setup_project.bat. If not, run the three commands in the file manually. The last command prompts you to create a superuser, which you'll use later to logon.
Install the Requests: HTTP for Humans module from the command line: pip install requests
Register the app in Azure Active Directory. The app should be registered as a web app with a Sign-on URL of "http://127.0.0.1:8000/contacts", and should be given permission to "Read users' contacts".
Edit the .\contacts\clientreg.py
file. Copy the client ID for your app obtained during app registration and paste it as the value for the id
variable. Copy the key you created during app registration and paste it as the value for the secret
variable. Save the file.
Start the development server: python manage.py runserver
You should see output like: Performing system checks...
System check identified no issues (0 silenced). December 18, 2014 - 12:36:32 Django version 1.7.1, using settings 'pythoncontacts.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK.
Use your browser to go to http://127.0.0.1:8000/contacts.
Login with your superuser account.
You should now be prompted to connect your Office 365 account. Click the link to do so and login with an Office 365 account.
You should see a table listing the existing contacts in your Office 365 account. You can click the "New Contact" button to create a new contact, or use the "Edit" or "Delete" buttons on existing contacts.
If you want to see what gets stored in the Django database for the user, go too http://127.0.0.1:8000/admin and click on the Office365 connections link. You can delete the user's record from the admin site too, in case you want to go through the consent process again.
To get a specific release version, go to https://github.com/jasonjoh/pythoncontacts/releases
Copyright (c) Microsoft. All rights reserved.
Connect with me on Twitter @JasonJohMSFT
Follow the Exchange Dev Blog