图 API 访问 oneDrive for business items/ffiles
Graph API to access oneDrive for business items/ffiles
我正在开发一个文档管理应用程序,用户应该能够访问 oneDrive 中的文件夹,有时在相同的 document/file 上工作,在应用程序中编辑、复制文档并将文档从应用程序上传到 oneDrive .这意味着该文件夹应该可供所有有权限的用户使用。当我使用自己的个人帐户时,我可以完成所有工作,例如,我正在使用此 url 从文件夹 X:"https://graph.microsoft.com/v1.0/me/drive/root:/folederX:/children"" 获取文件列表,一切正常。但是当我我使用的是企业帐户,它不起作用。我通过租户 ID 进行身份验证并获得正确的令牌,但之后我收到 400 错误。
现在,我真的很困惑,如果我想在这里实现的目标真的可以通过 oneDrive for business 实现,还是我们应该使用共享点?因为 folderX 显然是在 oneDrive 企业帐户中与我共享的,而它在我自己的 oneDrive 中不存在。
对不起,如果这个问题看起来很愚蠢,但我真的很困惑。
错误是:
This is error:
{ "error": { "code": "accessDenied", "message": "There has been an
error authenticating the request.", "innerError": { "request-id":
"230e946c-d81a-4bf1-903e-26d92c5441db", "date": "2019-09-20T10:12:38"
} } }
我了解到您正在尝试使用个人 Microsoft 帐户访问已在您客户的 OneDrive for business 中与您共享的文件。如有误会指正。
如果是这样,您需要使用the OAuth 2.0 code grant flow获取访问令牌。
首先,我假设您已将您的个人帐户作为来宾用户添加到客户的 Azure AD。并且该文件已与您的个人帐户共享。并且已在您客户的 Azure AD 中注册的应用程序中分配了正确的委派权限。
Request an authorization code 像这样:
https://login.microsoftonline.com/{Tenant ID of your customer}/oauth2/authorize?
client_id={app id of the app registered in your customer's Azure AD}
&response_type=code
&redirect_uri={redirect uri of the app registered in your customer's Azure AD}
&response_mode=query
&resource=https://graph.microsoft.com
&state=12345
您将收到这样的回复:
https://localhost/?code={code}&state=12345&session_state=54572324-6121-4add-85f8-22e3a815646b
请将"code"复制到这里以备后用。
然后您可以发送访问令牌请求:
将"jmaster.onmicrosoft.com"替换为您客户的租户并修改其他值(包括client_id、client_secret, redirect_uri and code) in Body.
获得访问令牌后,您可以发送访问共享文件的请求。
https://graph.microsoft.com/v1.0/users/{user id}/drive/root:/folederX:/children
请注意这里的 "user" 是与您共享文件的人。
我正在开发一个文档管理应用程序,用户应该能够访问 oneDrive 中的文件夹,有时在相同的 document/file 上工作,在应用程序中编辑、复制文档并将文档从应用程序上传到 oneDrive .这意味着该文件夹应该可供所有有权限的用户使用。当我使用自己的个人帐户时,我可以完成所有工作,例如,我正在使用此 url 从文件夹 X:"https://graph.microsoft.com/v1.0/me/drive/root:/folederX:/children"" 获取文件列表,一切正常。但是当我我使用的是企业帐户,它不起作用。我通过租户 ID 进行身份验证并获得正确的令牌,但之后我收到 400 错误。 现在,我真的很困惑,如果我想在这里实现的目标真的可以通过 oneDrive for business 实现,还是我们应该使用共享点?因为 folderX 显然是在 oneDrive 企业帐户中与我共享的,而它在我自己的 oneDrive 中不存在。 对不起,如果这个问题看起来很愚蠢,但我真的很困惑。
错误是:
This is error: { "error": { "code": "accessDenied", "message": "There has been an error authenticating the request.", "innerError": { "request-id": "230e946c-d81a-4bf1-903e-26d92c5441db", "date": "2019-09-20T10:12:38" } } }
我了解到您正在尝试使用个人 Microsoft 帐户访问已在您客户的 OneDrive for business 中与您共享的文件。如有误会指正。
如果是这样,您需要使用the OAuth 2.0 code grant flow获取访问令牌。
首先,我假设您已将您的个人帐户作为来宾用户添加到客户的 Azure AD。并且该文件已与您的个人帐户共享。并且已在您客户的 Azure AD 中注册的应用程序中分配了正确的委派权限。
Request an authorization code 像这样:
https://login.microsoftonline.com/{Tenant ID of your customer}/oauth2/authorize?
client_id={app id of the app registered in your customer's Azure AD}
&response_type=code
&redirect_uri={redirect uri of the app registered in your customer's Azure AD}
&response_mode=query
&resource=https://graph.microsoft.com
&state=12345
您将收到这样的回复:
https://localhost/?code={code}&state=12345&session_state=54572324-6121-4add-85f8-22e3a815646b
请将"code"复制到这里以备后用。
然后您可以发送访问令牌请求:
将"jmaster.onmicrosoft.com"替换为您客户的租户并修改其他值(包括client_id、client_secret, redirect_uri and code) in Body.
获得访问令牌后,您可以发送访问共享文件的请求。
https://graph.microsoft.com/v1.0/users/{user id}/drive/root:/folederX:/children
请注意这里的 "user" 是与您共享文件的人。