问题/如何使用 GRAPH API 获取我的 SharePoint 网站的文档库

问题描述 投票:0回答:1

如果我使用以下代码示例,我可以获得如下所示的 SharePoint 站点实体: enter image description here 但是应包含站点实体(其中有文档库)的驱动器实体的字段

drive
drives
None
。 另外,
lists
字段是
None
(AFAIK
drives
是一种特殊类型的
lists
,模板为“文档库”,所以我希望在这里看到所有内容)。 另一方面,直接使用我网站的仪表板,我可以从文档存储上传/下载文件: enter image description here

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())

我的问题是:

  1. 如果我在站点对象的任何字段中都没有看到我正在站点的仪表板中使用的文档库,如何才能看到它?它们之间有某种关联吗?
  2. 如果我希望管理此云端硬盘实体,如何根据我的代码片段并从
    site_id
    作为信息开始爬取正确的资源?
python azure sharepoint microsoft-graph-api onedrive
1个回答
0
投票

如果您有

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)
© www.soinside.com 2019 - 2024. All rights reserved.