使用来自GitHub的代码示例专门用于设置对OneDrive API的Python访问的身份验证(我开始认为这个源已经过时),我没能超过在执行后粘贴Microsoft提供的代码的部分程序..

Python代码:

import onedrivesdk

redirect_uri = 'https://login.microsoftonline.com/common/oauth2/nativeclient'
client_secret = '*this code omitted*'
client_id='*this code omitted*'
api_base_url='https://api.onedrive.com/v1.0/'
scopes=['onedrive.readwrite']

http_provider = onedrivesdk.HttpProvider()
auth_provider = onedrivesdk.AuthProvider(
    http_provider=http_provider,
    client_id=client_id,
    scopes=scopes)

client = onedrivesdk.OneDriveClient(api_base_url, auth_provider, http_provider)
auth_url = client.auth_provider.get_auth_url(redirect_uri)
# Ask for the code
print('Paste this URL into your browser, approve the app\'s access.')
print('Copy everything in the address bar after "code=", and paste it below.')
print(auth_url)
code = raw_input('Paste code here: ')

client.auth_provider.authenticate(code, redirect_uri, client_secret)

在浏览器中执行代码并粘贴网址后,会弹出一个弹出窗口,我会在其中验证我是否要让我的应用程序访问API ..我点击“确定” .

然后我会在URL任务栏中看到代码 . 我将代码复制并粘贴到程序中..

然后我得到的错误是:

raise Exception(str(message["error"]))

Exception: invalid_request

链接到使用的GitHub源:https://github.com/OneDrive/onedrive-sdk-python

注意:我必须省略范围,例如此列表中的前两个:

scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite']

因为它们显然不存在(根据Microsoft将URL粘贴到任务栏后提供的错误代码)

是否有更好的来源为Python程序设置身份验证以与OneDrive API进行通信?

我是一个相对较新的Python用户,您的耐心表示赞赏 .