首页 文章

列出共享文件OneDrive for business

提问于
浏览
1

我希望在OneDrive上列出与我共享的文件与Python OneDrive SDK(onedrive-python-sdk)

我已成功通过身份验证,并能够使用以下代码列出我拥有的文件

import onedrivesdk
from onedrivesdk.helpers import GetAuthCodeServer
from onedrivesdk.helpers.resource_discovery import ResourceDiscoveryRequest

redirect_uri = 'http://localhost:8080'
client_id = your_client_id
client_secret = your_client_secret
discovery_uri = 'https://api.office.com/discovery/'
auth_server_url='https://login.microsoftonline.com/common/oauth2/authorize'
auth_token_url='https://login.microsoftonline.com/common/oauth2/token'

http = onedrivesdk.HttpProvider()
auth = onedrivesdk.AuthProvider(http,
                                client_id,
                                auth_server_url=auth_server_url,
                                auth_token_url=auth_token_url)
auth_url = auth.get_auth_url(redirect_uri)
code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
auth.authenticate(code, redirect_uri, client_secret, resource=discovery_uri)
# If you have access to more than one service, you'll need to decide
# which ServiceInfo to use instead of just using the first one, as below.
service_info = ResourceDiscoveryRequest().get_service_info(auth.access_token)[0]
auth.redeem_refresh_token(service_info.service_resource_id)
client = onedrivesdk.OneDriveClient(service_info.service_resource_id + '/_api/v2.0/', auth, http)

#get the top three elements of root, leaving the next page for more elements
collection = client.item(drive='me', id='root').children.request(top=3).get()
# print files
print collection

但是我不知道怎么请求 files that have been shared with me ,我've seen references in the OneDrive API to use the following request, but I'我不知道怎么打电话

GET /drive/view.sharedWithMe

任何帮助,将不胜感激

1 回答

  • 0

    我将在这个答案的前面添加一个免责声明,我没有设置环境来验证这个python解决方案,但我相信它应该可行(或者最坏的情况为你提供解决它的想法) .

    你是正确的,因为当前的SDK没有公开 view.sharedWithMe ,但幸运的是它包含你自己需要的工具 . 您将希望将 append_to_request_url 函数与 ItemsCollectionRequestBuilder 结合使用,如下所示:

    collection = ItemsCollectionRequestBuilder(client.drive.append_to_request_url("view.sharedWithMe"), client).request(top=3).get()
    

    希望这会给你你想要的结果 .

相关问题