python - 使用 python Office 365 API 获取 Sharepoint 文件的最后修改日期/时间
问题描述
我需要使用 SharePoint REST API for python 获取 SharePoint 中文档的最后修改日期
基本上我想从 SharePoint 网站获取最近修改的文件 我想获取最后修改日期以验证当前文档是否是最新的
我正在尝试查找是否有任何方法可以帮助获取文档的最后修改日期。
解决方案
我建议使用 O365 Python 包。
https://github.com/O365/python-o365
下面的示例显示了如何打印修改时间然后下载文件。在此示例中,我正在下载 excel 文件。
注意:我所有的密码等都存储在我创建的设置文件中的字典中,因此您为什么看到我导入该文件。这不是必需的,是个人喜好。
from O365 import Account
from settings import settings
save_path = "\path\to\save\file\\"
# user log in information using client credentials and client id for Microsoft Graph API
credentials = (settings['client_credentials']['client_id'],
settings['client_credentials']['client_secret'])
# the default protocol will be Microsoft Graph
account = Account(credentials, auth_flow_type='credentials',
tenant_id=settings['client_credentials'
]['client_tenant_id'])
if account.authenticate():
print('Authenticated!')
# initiate share_point account
share_point = account.sharepoint()
# change this site id to whatever your SharePoint site id is
site_id = 'your site id'
# get the site
site = share_point.get_site(site_id)
# create drive item
my_drive = site.get_default_document_library()
# navigate to root folder of the drive
root_folder = my_drive.get_root_folder()
# this will get all the folders under your root folder
child_folders = root_folder.get_child_folders()
for folder in child_folders:
if folder.name == 'Your SharePoint folder name':
for item in folder.get_items():
try:
if item.name.lower().endswith(('.xls', '.xlsx')):
# print last modified date
print(item.modified)
# download files
item.download(save_path)
except Exception, e:
print('File not found!')
print(e)
推荐阅读
- python - 如果错误点与“application = get_wsgi_application()”一致,如何查找原因
- ios - `podspec` 规范不验证
- sql-update - 数据仓库事实表中的更新
- mysql - 在为 Wordpress 网站排序此索引时,如何减少 MYSQL 的使用?
- html - 如何使用 VBA 在网站中单击下拉菜单选项?
- maven - 生成 maven springboot 版本化应用程序
- javascript - 通过 props 传递函数
- intellij-idea - 从 git bash 在 IntelliJ 中打开 java 项目
- c# - 带有 SignalR 集线器的 ASP.NET Core 中的范围服务
- javascript - 打字稿静态类