嗨,有一种方法可以从 API 中获取所有站点吗?
我可以访问带有 url 的站点,但是可以获取带有 url 的站点列表并对其进行迭代吗?
非常感谢
你好,你有关于这个话题的消息吗? 或者一些解决方法? 不着急只有好奇谢谢^^
嘿,
肯定的,它支持检索租户内的所有网站(网站集),例如通过方法Tenant.get_site_properties_from_sharepoint_by_filters(filter, start_index=0, include_detail)
例子
该示例演示了如何检索租户内的所有站点并打印其 url:
from office365.runtime.auth.user_credential import UserCredential
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.tenant.administration.site_properties import SiteProperties
from office365.sharepoint.tenant.administration.tenant import Tenant
from settings import settings
credentials = UserCredential(username, password)
admin_client = ClientContext("https://{tenant-prefix}-admin.sharepoint.com/").with_credentials(credentials)
tenant = Tenant(admin_client)
result = tenant.get_site_properties_from_sharepoint_by_filters("", 0).execute_query()
for siteProps in result: # type: SiteProperties
print(siteProps.get_property('Url'))
嗨@vgrem谢谢你的代码,但遗憾的是,我没有得到 url,只有 None、None、None……但我可以使用我的凭据访问 sharepoint 上的站点列表,因此我认为问题不是我的权限. 你知道可能是什么问题吗?
@oktorok啊, siteProps.get_property('Url')
可能是这种情况,因为最近get_property
语义已更改。
你能不能用这个语法再试一次:
print(siteProps.properties.get('Url'))
是的,现在有效地工作了,非常感谢。