【问题标题】:List shared files OneDrive for business列出共享文件 OneDrive for business
【发布时间】:2017-02-22 19:37:56
【问题描述】:

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

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

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

任何帮助将不胜感激

【问题讨论】:

    标签: python onedrive


    【解决方案1】:

    我会在这个答案的前面加上一个免责声明,即我没有设置环境来验证这个 python 解决方案,但我相信它应该可以工作(或者在最坏的情况下为您提供解决它的想法)。

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

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

    希望这会给您带来您所追求的结果。

    【讨论】:

    • 感谢您的快速回答,这绝对是一种享受!
    • @user29184827194701 以后可以在哪里下载文件?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-14
    相关资源
    最近更新 更多