-
Notifications
You must be signed in to change notification settings - Fork 2
/
update.py
38 lines (30 loc) · 1.2 KB
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: UTF-8 -*-
import requests as req
import json,sys,time
#先注册azure应用,确保应用有以下权限:
#files: Files.Read.All、Files.ReadWrite.All、Sites.Read.All、Sites.ReadWrite.All
#user: User.Read.All、User.ReadWrite.All、Directory.Read.All、Directory.ReadWrite.All
#mail: Mail.Read、Mail.ReadWrite、MailboxSettings.Read、MailboxSettings.ReadWrite
#注册后一定要再点代表xxx授予管理员同意,否则outlook api无法调用
path=sys.path[0]+r'/1.txt'
def gettoken(refresh_token):
headers={'Content-Type':'application/x-www-form-urlencoded'
}
data={'grant_type': 'refresh_token',
'refresh_token': refresh_token,
'client_id':id,
'client_secret':secret,
'redirect_uri':'http://localhost:53682/'
}
html = req.post('https://login.microsoftonline.com/common/oauth2/v2.0/token',data=data,headers=headers)
jsontxt = json.loads(html.text)
refresh_token = jsontxt['refresh_token']
access_token = jsontxt['access_token']
with open(path, 'w+') as f:
f.write(refresh_token)
def main():
fo = open(path, "r+")
refresh_token = fo.read()
fo.close()
gettoken(refresh_token)
main()