如何使用图谱api在Django中使用POST请求?

问题描述 投票:1回答:1

[基本上,我正在尝试创建一个表单,该表单将在我的Azure Active Directory中创建一个新用户。根据Microsoft document,我需要使用给定的HTTP请求。有人可以指导我如何实现它吗?如果提供了代码,那么它会很棒,否则解释或指导也很棒。

我已经能够通过GET请求成功运行教程代码。现在,我希望使用graph_client.post(https://graph.microsoft.com/v1.0/users,data = {'userPrincipalName':'[email protected]',等等...))结构类型进行POST请求。不幸的是,这会生成HTTP 400消息,其格式为“代码”:“ BadRequest”,“消息”:“实体仅允许使用JSON Content-Type标头进行写入”。本教程的结构是否可以处理POST请求?

如果可以指导我在哪里添加行以使POST方法成功工作。我正在附上我的代码的屏幕截图,请在下面找到:-

HTML页面:-enter image description here

views.py:-enter image description here

graph_helper.py;-enter image description here

您的时间和精力将不胜感激。谢谢...

microsoft-graph azure-ad-graph-api instagram-graph-api microsoft-graph-mail
1个回答
0
投票

要调用Microsoft Graph API,必须在请求标头中提供访问令牌。这是请求的示例。

POST https://graph.microsoft.com/v1.0/users
Content-type: application/json

{
  "accountEnabled": true,
  "displayName": "displayName-value",
  "mailNickname": "mailNickname-value",
  "userPrincipalName": "[email protected]",
  "passwordProfile" : {
    "forceChangePasswordNextSignIn": true,
    "password": "password-value"
  }
}

enter image description here

有两种获取身份验证令牌的方法。

Get access on behalf of a user

Get access without a user

© www.soinside.com 2019 - 2024. All rights reserved.