我正在尝试使用适用于Python的OneDrive 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]
它将我重定向到我的Microsoft帐户的microsoft登录页面,此后,我得到以下错误:
KeyError Traceback (most recent call last)
<ipython-input-38-099411646fc4> in <module>()
4 # If you have access to more than one service, you'll need to decide
5 # which ServiceInfo to use instead of just using the first one, as below.
----> 6 service_info = ResourceDiscoveryRequest().get_service_info(auth.access_token)[0]
7 auth.redeem_refresh_token(service_info.service_resource_id)
8 client = onedrivesdk.OneDriveClient(service_info.service_resource_id + '/_api/v2.0/', auth, http)
C:\Anaconda3\lib\site-packages\onedrivesdk\helpers\resource_discovery.py in get_service_info(self, access_token)
24 headers = {'Authorization': 'Bearer ' + access_token}
25 response = json.loads(requests.get(self._discovery_service_url, headers=headers).text)
---> 26 service_info_list = [ServiceInfo(x) for x in response['value']]
27 trimmed_service_info_list = [si for si in service_info_list
28 if si.capability == 'MyFiles' and si.service_api_version == 'v2.0']
KeyError: 'value'
有人可以帮助我解决问题吗?