使用python Office 365 API获取Sharepoint文件的上次修改日期/时间
我需要使用SharePoint rest API for python获取SharePoint中文档的最后修改日期 基本上,我想从SharePoint网站获取最近修改的文件我想获取上次修改的日期,以验证当前文档是否为最新文档使用python Office 365 API获取Sharepoint文件的上次修改日期/时间,python,python-3.x,office365api,last-modified,Python,Python 3.x,Office365api,Last Modified,我需要使用SharePoint rest API for python获取SharePoint中文档的最后修改日期 基本上,我想从SharePoint网站获取最近修改的文件我想获取上次修改的日期,以验证当前文档是否为最新文档 我正在尝试寻找是否有任何方法可以帮助获取文档的最后修改日期。我建议使用O365 Python包 下面的示例显示如何打印修改的时间,然后下载文件。在本例中,我下载excel文件 注意:我的所有密码等都存储在我创建的设置文件中的字典中,因此您看到我导入该文件的原因。这不是必需
我正在尝试寻找是否有任何方法可以帮助获取文档的最后修改日期。我建议使用O365 Python包 下面的示例显示如何打印修改的时间,然后下载文件。在本例中,我下载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)
你找到答案了吗?