简体   繁体   English

通过邮递员调用微软图api

[英]calling microsoft graph api via postman

Good day SO people. 美好的一天SO人。

I am trying to create a REST web service to access MS Graph Calendar API. 我正在尝试创建一个REST Web服务来访问MS Graph Calendar API。 I would like to test this via postman first before I start to code. 在开始编码之前,我想先通过邮递员对此进行测试。 After some researching below is what I've reached so far. 经过一些研究后,到目前为止我已经达到了。

  1. Created a Microsoft account with @outlook.com as domain and accessed the outlook utility. 使用@ outlook.com作为域创建了一个Microsoft帐户,并访问了outlook实用程序。 I went to the calendar display and plotted some events on the calendar. 我去了日历显示屏并在日历上绘制了一些事件。
  2. Used the account to enter Azure portal and created an Azure Active Directory and a new user in this tenant. 使用该帐户进入Azure门户并在此承租人中创建Azure Active Directory和新用户。 I shared the calendar of my Microsoft account to this newly created AAD user. 我将我的Microsoft帐户的日历共享给这个新创建的AAD用户。
  3. Used the newly created Azure active directory user to login into Microsoft App Registration Portal . 使用新创建的Azure活动目录用户登录Microsoft App Registration Portal I used this user because I saw in a blog that I need to register an application under "Converged Application". 我使用过这个用户,因为我在博客中看到我需要在“融合应用程序”下注册一个应用程序。 When I use my Microsoft account, there is no Converged Application section in the Application Registration Portal. 当我使用我的Microsoft帐户时,应用程序注册门户中没有Converged Application部分。 Below is a screen capture. 下面是一个截屏。

  1. I added a "Converged Application" and got the necessary details like the Application ID and Application Secret Key . 我添加了一个“融合应用程序”,并获得了应用程序ID应用程序密钥等必要的详细信息。 The platform that I chose is "Web" and I supplied this as redirect URL: https://www.getpostman.com/oauth2/callback . 我选择的平台是“Web”,我将其作为重定向URL提供: https://www.getpostman.com/oauth2/callbackhttps://www.getpostman.com/oauth2/callback Although, I think I won't be using this because what I need is a seamless login. 虽然,我想我不会使用它,因为我需要的是无缝登录。 I don't want to spawn a browser for me to supply my Microsoft account for authorization and authentication. 我不想为我生成一个浏览器来提供我的Microsoft帐户进行授权和身份验证。

Upon reading, there are many grant types for you to be authorized and authenticated to use MS Graph APIs. 在阅读时,有许多授权类型供您授权和验证以使用MS Graph API。 One is Authorization Code Grant Flow which spawns an interface for you to sign-in your Microsoft or AAD account. 一个是授权代码授权流程 ,它为您提供登录Microsoft或AAD帐户的界面。 As mentioned above I need the seamless login so I've tried Client Credentials Grant Type and Resource Owner Grant Type . 如上所述,我需要无缝登录,所以我尝试过Client Credentials Grant TypeResource Owner Grant Type

  1. Upon creating the application, there are privileges that should be granted to it to control what it can access. 在创建应用程序时,应该授予它以控制它可以访问的权限。 I've given the required Delegated and Application permissions to the application in line with the specific MS Graph API that I need to use. 我已根据我需要使用的特定MS Graph API向应用程序提供了所需的委托和应用程序权限。 Below is a screen capture. 下面是一个截屏。

  1. Assuming that I'm all set, I tried to get an access token using this URL: 假设我已经完成设置,我尝试使用此URL获取访问令牌:

    https://login.microsoftonline.com/substitute-with-tenant-directory-id/oauth2/v2.0/token https://login.microsoftonline.com/substitute-with-tenant-directory-id/oauth2/v2.0/token

I was able to get an access token using the resource owner grant type. 我能够使用资源所有者授权类型获取访问令牌。 Below is the screen capture. 下面是截屏。

  1. Next, I tried to access the specific API that I need. 接下来,我尝试访问我需要的特定API。 Here is the URL: 这是URL:

    https://graph.microsoft.com/v1.0/me/calendar/calendarView?startDateTime=2018-08-01T00:00:00.0000000&endDateTime=2018-08-31T23:59:59.0000000 https://graph.microsoft.com/v1.0/me/calendar/calendarView?startDateTime=2018-08-01T00:00:00.0000000&endDateTime=2018-08-31T23:59:59.0000000

I've also tried to replace the "me" part in the URL with "users/substitute-with-user-id" but unfortunately I'm getting an error. 我还尝试用“users / substitute-with-user-id”替换URL中的“我”部分,但不幸的是我收到了错误。 Below is the screen capture. 下面是截屏。

I'm stuck because the response says "Unknown Error". 我被卡住,因为响应显示“未知错误”。 Does anybody know what I am missing here? 有人知道我在这里缺少什么吗?

It is delegated permission token, you can only get current login user's calendar event. 它是委派权限令牌,您只能获取当前登录用户的日历事件。 If you want to load other user's event, you can use app-only token. 如果要加载其他用户的事件,可以使用仅限app的令牌。 Refer to https://developer.microsoft.com/en-us/graph/docs/concepts/auth_v2_service to know how to get app-only token. 请参阅https://developer.microsoft.com/en-us/graph/docs/concepts/auth_v2_service以了解如何获取仅限app的令牌。

I have recently called Graph API via postman by following the steps given on This Blog and I think the issue is you are not passing Resource in body. 我最近通过邮递员按照本博客上给出的步骤调用了图谱API,我认为问题是你没有在正文中传递Resource Try to pass the Resource in a body with value https://graph.microsoft.com hope this will solve your issue. 尝试在值为https://graph.microsoft.com的正文中传递Resource ,希望这将解决您的问题。

Below things worked for me: 以下事情对我有用:

https://blogs.msdn.microsoft.com/softwaresimian/2017/10/05/using-postman-to-call-the-graph-api-using-azure-active-directory-aad/ https://blogs.msdn.microsoft.com/softwaresimian/2017/10/05/using-postman-to-call-the-graph-api-using-azure-active-directory-aad/

1) Create a access token from Authorization tab, select the type as OAuth 2.0 and click on GET NEW ACCESS TOKEN. 1)从授权选项卡创建访问令牌,选择类型为OAuth 2.0,然后单击GET NEW ACCESS TOKEN。

2) Enter the details like below: 2)输入如下详细信息:

Auth URL : https://login.windows.net/common/oauth2/authorize?resource=https://outlook.office.com 验证URL: https//login.windows.net/common/oauth2/authorize? resources = https://outlook.office.com

Access Token URL : https://login.microsoftonline.com/common/oauth2/token 访问令牌URL: https//login.microsoftonline.com/common/oauth2/token

Client ID: your application id 客户端ID:您的应用程序ID

Secret: secret set while app registration. 秘密:app注册时的秘密设置。

3) It will authenticate and token will be created. 3)它将进行身份验证并创建令牌。

4) Select Add token to Header and click on Use Token button. 4)选择Add token to Header并单击Use Token按钮。

5) In Body tab select x-www-form. 5)在Body选项卡中选择x-www-form。

6) In Header tab it should look like below: 6)在标题选项卡中,它应如下所示:

Content-Type : application/x-www-form-urlencoded 内容类型:application / x-www-form-urlencoded

Authorization : Bearer (your token generated automatically). 授权:承载(您的令牌自动生成)。

7) Perform POST Operation. 7)执行POST操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM