【问题标题】:R httr MS Dataverse API: Bad Request (HTTP 400), Define scopeR httr MS Dataverse API:错误请求(HTTP 400),定义范围
【发布时间】:2021-12-01 00:33:04
【问题描述】:

我的问题与这个问题密切相关:R httr Linkedin API: Bad Request (HTTP 400)

我在 Azure AD 中设置了一个应用程序,我想用它使用 R 从 MS Dataverse 中获取数据。我是 API 新手,所以我首先在 Postman 中设置它。我在 Postman 中成功获取了我的数据,但它不需要 Scope 参数。

我试图在 R 中重新创建我在 Postman 中所做的...

require(rvest)

dataverse_api = oauth_endpoint(request = NULL, 
   authorize = "REDACTED",
   access = "REDACTED",
   base_url = "REDACTED")

API.Key = "REDACTED"
API.Secret = "REDACTED"

App = oauth_app("EPS Project Development", key = API.Key, secret = API.Secret)

API.token = oauth2.0_token(dataverse_api, App)

这导致我的浏览器打开并给我一个错误,说需要一个范围。我一直在搜索文档以查找范围的命名法,但没有成功。我发现了几个文档(12 等),它们有些外围,列出了诸如“ReadWrite.All”或“Files.ReadWrite.All”之类的选项,但我的理解是这些权限是与范围不同。因为我不知道自己在做什么,所以我尝试了其中的几个:

require(rvest)

dataverse_api = oauth_endpoint(request = NULL, 
   authorize = "REDACTED",
   access = "REDACTED",
   base_url = "REDACTED")

API.Key = "REDACTED"
API.Secret = "REDACTED"

App = oauth_app("EPS Project Development", key = API.Key, secret = API.Secret)

API.token = oauth2.0_token(dataverse_api, App, scope = "User_impersonation")

结果总是一样的。浏览器打开时显示一条消息 Authentication complete. Please close this page and return to R.,但在 R 中我得到:

Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
Error in oauth2.0_access_token(endpoint, app, code = code, user_params = user_params,  : 
  Bad Request (HTTP 400). Failed to get an access token.

从我上面引用的类似问题的链接中,我了解到我仍然缺少 Scope 参数。但我不知道从哪里获得 MS Dataverse 的 Scope 参数。有人可以帮忙吗?

【问题讨论】:

  • 您也应该尝试询问 openid 范围,这有帮助吗?
  • 感谢您的回复。我对这个词很陌生。什么是 openid 范围?我该向谁要求呢?
  • 范围是您尝试访问的内容,如果您想使用 AzureAD 进行身份验证,我认为您还需要添加 openid 范围,请参阅docs.microsoft.com/en-us/azure/active-directory/develop/…
  • 这很有帮助;谢谢托雷!

标签: r oauth-2.0 powerapps httr dataverse


【解决方案1】:

我不知道是否有其他选项,但如果它对其他人有帮助,我可以通过将范围指定为 Dynamics 365 URL 后跟 .default 来使其工作。对我来说,这看起来像:https://org593dc393.crm4.dynamics.com/.default

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-21
    • 2016-11-18
    • 1970-01-01
    相关资源
    最近更新 更多