如果我使用以下代码示例,我可以获得如下所示的 SharePoint 站点实体: 但是应包含站点实体(其中有文档库)的驱动器实体的字段
drive
或 drives
是 None
。
另外,lists
字段是None
(AFAIK drives
是一种特殊类型的lists
,模板为“文档库”,所以我希望在这里看到所有内容)。
另一方面,直接使用我网站的仪表板,我可以从文档存储上传/下载文件:
import os
import jwt
from typing import Optional, Literal
from azure.identity.aio import ClientSecretCredential
from msgraph import GraphServiceClient
from msgraph.generated.models.drive_item import DriveItem
from msgraph.generated.models.folder import Folder
from msgraph.generated.drives.item.items.item.content.content_request_builder import ContentRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
from msgraph.generated.models.o_data_errors.o_data_error import ODataError
from src.config.loader import CONFIG
import aiofiles
from src.utils.logger import get_logger
logger = get_logger(CONFIG.logging.name, CONFIG.logging.level)
class GraphClientSingleton():
_client = None
_credentials = None
@classmethod
def get_client(cls):
if cls._client is None:
# cls._authority = 'login.microsoftonline.com'
cls._credentials = ClientSecretCredential(
tenant_id = CONFIG.msgraph.tenant_id_sharepoint,
client_id = CONFIG.msgraph.client_id_sharepoint,
client_secret = CONFIG.msgraph.client_secret_sharepoint,
)
cls._scopes = ['https://graph.microsoft.com/.default']
cls._client = GraphServiceClient(credentials=cls._credentials, scopes=cls._scopes)
return cls._client
if __name__ == "__main__":
async def test_api():
sp_dao = SharePointDAO()
site_id = ... # my site id
site = await sp_dao.client.sites.by_site_id(site_id).get()
logger.info(site)
import asyncio
asyncio.run(test_api())
我的问题是:
site_id
作为信息开始爬取正确的资源?如果您有
siteId
,您可以通过调用列出所有文档库
result = await graph_client.sites.by_site_id('site-id').drives.get()
或扩展
drives
关系
query_params = SiteItemRequestBuilder.SiteItemRequestBuilderGetQueryParameters(
expand = ["drives"],
)
request_configuration = RequestConfiguration(
query_parameters = query_params,
)
result = await graph_client.sites.by_site_id('site-id').get(request_configuration = request_configuration)