列出共享文件OneDrive for business

时间:2017-02-22 19:37:57

标签: python onedrive

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

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

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

但是我不确定如何申请与我共享的文件,我看到OneDrive API中的引用使用了以下请求,但我不确定拨打电话

GET /drive/view.sharedWithMe

任何帮助将不胜感激

1 个答案:

答案 0 :(得分: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()

希望这会为您提供您之后的结果。