代码拉取完成,页面将自动刷新
同步操作将从 YanceyGao/AutoApiSecret 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# -*- 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'
num1 = 0
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)
return access_token
def main():
fo = open(path, "r+")
refresh_token = fo.read()
fo.close()
global num1
localtime = time.asctime( time.localtime(time.time()) )
access_token=gettoken(refresh_token)
headers={
'Authorization':access_token,
'Content-Type':'application/json'
}
try:
if req.get(r'https://graph.microsoft.com/v1.0/me/drive/root',headers=headers).status_code == 200:
num1+=1
print("1调用成功"+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/me/drive',headers=headers).status_code == 200:
num1+=1
print("2调用成功"+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/drive/root',headers=headers).status_code == 200:
num1+=1
print('3调用成功'+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/users ',headers=headers).status_code == 200:
num1+=1
print('4调用成功'+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/me/messages',headers=headers).status_code == 200:
num1+=1
print('5调用成功'+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messageRules',headers=headers).status_code == 200:
num1+=1
print('6调用成功'+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages/delta',headers=headers).status_code == 200:
num1+=1
print('7调用成功'+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/me/drive/root/children',headers=headers).status_code == 200:
num1+=1
print('8调用成功'+str(num1)+'次')
if req.get(r'https://api.powerbi.com/v1.0/myorg/apps',headers=headers).status_code == 200:
num1+=1
print('8调用成功'+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/me/mailFolders',headers=headers).status_code == 200:
num1+=1
print('9调用成功'+str(num1)+'次')
if req.get(r'https://graph.microsoft.com/v1.0/me/outlook/masterCategories',headers=headers).status_code == 200:
num1+=1
print('10调用成功'+str(num1)+'次')
print('此次运行结束时间为 :', localtime)
except:
print("pass")
pass
for _ in range(5):
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。