これは私がやっていることです。仕事用アカウントを使用してOffice 365のカレンダーにアクセスできない
Microsoft Azureを通じてMicrosoft Graph APIを使用して、Office 365テナントのカレンダーにアクセスして管理できるアプリケーションを開発したいと考えています。同社には、10人のユーザーを持つOffice 365 BusinessとAzure Active Directoryへのアクセスがあります。私はPython 3.5を使用していて、ライブラリに 承認コード許可フローをレイアウトするよう要求しています。
Windows Azure Active Directoryに自分のアプリケーションを登録し、このアプリケーションに必要なすべてのアクセス許可と返信URLを提供しました。クライアント秘密鍵も発行されています。トークン
を取得し、第二にdef triggerAutorization(request):
state = str(uuid4())
payload = {
"client_id": client_id,
"response_type": "code",
"state": state,
"redirect_uri": "http://localhost:8000/authorized",
"prompt": "consent"
}
url = "https://login.microsoftonline.com/{tenant}/oauth2/authorize?" + urllib.parse.urlencode(payload)
return HttpResponseRedirect(url)
:Autorizationコードを取得し、まず
:ここ https://graph.microsoft.io/en-us/docs/authorization/app_authorization
、私は続くプロセス:
は、私は次のリンクを読んでdef requestToken(request):
headers = { 'Content-Type' : "application/x-www-form-urlencoded"}
post_data = {
"client_id": client_id,
"client_secret": client_secret,
"code" : request.session['code'],
"redirect_uri" : "http://localhost:8000/authorized",
"grant_type": "authorization_code",
"resource": "https://graph.microsoft.com/"
}
raw_response = requests.post("https://login.microsoftonline.com/{tenant}/oauth2/token?", data=post_data, headers= headers)
json_response = raw_response.json()
if json_response['access_token']:
request.session['access_token'] = json_response['access_token']
return HttpResponseRedirect('/createquote')
それは結構です
第三に、すべては、私がアクセスカレンダーへの権利(私は仮定)をトークンに沿ってアクセスを得た:
'scope': 'Calendars.Read Calendars.Read.All Calendars.Read.Shared Calendars.ReadWrite Calendars.ReadWrite.All Contacts.Read.Shared Directory.AccessAsUser.All Directory.Read.All Files.Read Files.Read.All Files.Read.Selected Files.ReadWrite Files.ReadWrite.All Mail.Read Mail.ReadWrite.All Mail.Send Mail.Send.All openid profile User.Read User.Read.All User.ReadBasic.All',
'expires_on': '1485932306',
'refresh_token': 'AQAB..',
'resource': 'https://graph.microsoft.com/',
'token_type': 'Bearer',
'expires_in': '3600',
'ext_expires_in': '0',
'not_before': '1485928406',
'access_token': 'eyJ0...',
'id_token': 'eyJ0...'
第四に、問題はここに来て、私はAPI呼び出しを作るしようとすると、応答が500のサーバーエラーであり、意味のある詳細はないためです。
def getCalendarList(request):
token = request.session['access_token']
headers = {
'User-Agent' : 'pythoncontacts/1.2',
'Authorization' : 'bearer {0}' . format(token),
'Content-Type' :"application/json;odata.metadata=minimal;odata.streaming=true"
}
request_id = str(uuid.uuid4())
instrumentation = { 'client-request-id' : request_id,
'return-client-request-id' : 'true' }
headers.update(instrumentation)
raw_response = requests.get("https://graph.microsoft.com/v1.0/me/calendars", headers = headers)
json_response = raw_response.json()
return HttpResponse(" %s" %str(json_response))
面白いことに、私は「https://graph.microsoft.com/v1.0/me/」とのAPIコールを変更すると、それが動作することです。
コミュニティ、あなたが私を助けてくれることを願っています。私は数多くのドキュメントを読んで、さまざまなアプローチを試みましたが、これを動作させることはできませんでした。
多くのありがとうございます。
多くの方にご注目ください。
このユーザーのデフォルトカレンダーはhttps://outlook.offfice365.comで確認できますか?また、Exchange Onlineを使用しているか、Exchange Onlineを使用しているビジネスライセンスがあるかについては、説明からは分かりません。 –
Marc LaFleurに感謝します。 !! :-) –