Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
身份验证OneDrive API Python_Python_Api_Authentication_Onedrive - Fatal编程技术网

身份验证OneDrive API Python

身份验证OneDrive API Python,python,api,authentication,onedrive,Python,Api,Authentication,Onedrive,使用来自GitHub的代码示例,该示例专门用于设置对OneDrive API的Python访问的身份验证(我开始认为该源代码已经过时),我无法通过执行程序后粘贴Microsoft提供的代码的部分 Python代码: import onedrivesdk redirect_uri = 'https://login.microsoftonline.com/common/oauth2/nativeclient' client_secret = '*this code omitted*' client

使用来自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)
在浏览器中执行代码并粘贴url后,会出现一个弹出窗口,我在其中验证我是否希望让我的应用程序访问API。。我点击“Ok”

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

那么我得到的错误是:

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

Exception: invalid_request
使用的GitHub源链接:

注意:我不得不省略范围,例如列表中的前两个:

scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite']
因为它们显然不存在(根据微软在将URL粘贴到任务栏后提供的错误代码)

是否有更好的源代码来设置Python程序与OneDrive API通信的身份验证


我是一个相对较新的Python用户,非常感谢您的耐心。

我遇到了同样的问题,解决方案是在应用程序注册中包含重定向uri

这可以在und Azure Active Directory>应用程序注册>“您的应用程序”>身份验证中完成。在我的例子中,我需要添加重定向URI

我在这里找到了建议:


希望它能帮助人们节省一些时间。

您在应用程序注册中选择了哪些范围而不是不再存在的范围?