Comments (6)
Thanks @barry-scott for your feedback. What sort of project are you trying to incorporate with? We do not have a command-line based tutorial for Python currently. Command line apps would use a different auth flow which may nor may not be applicable to your scenario. If you can share some details on your project I may be able to at least point you in the right direction.
from msgraph-sample-pythondjangoapp.
I am working on a PyQt5 app that runs on a touch screen.
What I need is an example that shows how to get calendar events from OWA.
How do I setup the app key?
How do I query events?
I do not need to be shown how to build those details in to my app.
If you look at google's calendard API example for the sort of thing I was hoping to find for graph API:
https://developers.google.com/calendar/quickstart/python
from msgraph-sample-pythondjangoapp.
Ok. It's not going to be all that different from this Django-based sample. You'll use the same packages, but the auth flow will be different since you're on a mobile device. The API calls are exactly the same.
Dependencies
- msal to manage authentication and token acquisition.
- requests for making HTTP requests to the Graph API endpoint.
App registration
Register an app at https://aad.portal.azure.com.
- Redirect URI: Public client/native (mobile & desktop),
http://localhost
Copy your Application (client) ID from the overview page. If you chose Accounts in this organizational directory only when creating the registration, you'll also need to copy your Directory (tenant) ID.
Code
import requests
from msal import PublicClientApplication
# Register your app in Azure AD to get an application ID
client_id = 'YOUR_APP_ID_HERE'
# If you register your app for any organization, leave as common
# If you register it for only users in your organization, change to
# your tenant ID
tenant_id = 'common'
# Array of Microsoft Graph scopes you need
scopes = [ 'User.Read', 'Calendars.Read' ]
if __name__ == '__main__':
# Create MSAL public client
app = PublicClientApplication(
client_id,
authority = 'https://login.microsoftonline.com/{0}'.format(tenant_id))
result = None
# Check for accounts in cache
accounts = app.get_accounts()
if accounts:
# For simplicity use the first account
user_account = accounts[0]
# Acquire the token silently
result = app.acquire_token_silent(scopes, user_account)
if not result:
# No accounts in the cache, get a token interactively
result = app.acquire_token_interactive(scopes)
if 'access_token' in result:
access_token = result['access_token']
user_response = requests.get(
'https://graph.microsoft.com/v1.0/me',
headers = {
'Authorization': 'Bearer {0}'.format(access_token)
}
)
user = user_response.json()
if 'displayName' in user:
print('Hello {0}'.format(user['displayName']))
else:
print(user)
calendar_response = requests.get(
'https://graph.microsoft.com/v1.0/me/calendarView',
headers = {
'Authorization': 'Bearer {0}'.format(access_token)
},
params = {
'startDateTime': '2021-05-03T00:00:00Z',
'endDateTime': '2021-05-10T00:00:00Z',
'$select': 'subject, start, end'
}
)
print(calendar_response.json())
else:
print(result.get('error'))
print(result.get('error_description'))
print(result.get('correlation_id'))
from msgraph-sample-pythondjangoapp.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.
from msgraph-sample-pythondjangoapp.
Thanks I will test that example shortly.
from msgraph-sample-pythondjangoapp.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.
from msgraph-sample-pythondjangoapp.
Related Issues (20)
- Sign in does not work HOT 6
- Home Page is Not rendering after Providing Credentials HOT 12
- Question about Tutorial code HOT 1
- Not pulling calendar events HOT 3
- Replace get_sign_in_url with get_sign_in_flow
- Update documentation HOT 1
- Syntax Error on Raise From in Manage.py because of the shebang line? HOT 4
- settings.py needs to be updated for templates and static folders HOT 5
- Redirection to the incorrect locale HOT 3
- is user_athenticated not being set to true on login HOT 6
- ValueError ("state missing from auth_code_flow") HOT 4
- authority issue needs to be discussed in tutorial HOT 2
- Unauthenticated user cannot access the site. HOT 1
- Tutorial part 3: Sign-In throws error - localhost refused to connect. HOT 4
- Authentication Problem - ValueError at /callback HOT 1
- Why is pycparser needed? HOT 2
- Use the O365 package? HOT 2
- Quickstart Fails to Authenticate. HOT 8
- Unauthenticated User Exception HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msgraph-sample-pythondjangoapp.