Microsoft Graph接口对接说明
-
授权请求,获取code
url: https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/authorize
请求方式:GET请求参数:
属性属性名类型备注tenantentId 租户Id string 目录(租户) ID client_id 应用程序Id string 应用程序(客户端) ID response_type 授权码code string code 默认使用 redirect_uri 应用程序的 redirect_uri string 重定向地址 https://teams.microsoft.com/ response_mode response mode string 指定用于将结果令牌发送回应用的方法。可以是 query或form_postscope 权限范围 string API权限名称,多个权限使用空格隔开 state 状态 int 状态 参考接口:https://login.microsoftonline.com/b243e90b-187c-415d-925f-5ceeced7e4de/oauth2/v2.0/authorize?
client_id=47f20b66-8559-47de-898d-1a331e96f5a5&
response_type=code&
redirect_uri=https://teams.microsoft.com/&
response_mode=query&scope=Calendars.Read&state=12345
请求上述接口后,会跳转到teams页面,完成teams的登录后,浏览器路径中会返回code,该code值在后续的获取token接口调用中会被使用到
2. 获取token
url:https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token
请求方式:POST
请求参数 x-www-form-urlencoded
|
属性
|
属性名
|
类型
|
备注
|
|---|---|---|---|
|
属性
|
属性名
|
类型
|
备注
|
| tenantentId | 租户Id | string | 目录(租户) ID |
| client_id | 应用程序Id | string | 应用程序(客户端) ID |
| code | 授权码code | string | 上述接口返回code值 |
| redirect_uri | 应用程序的 redirect_uri | string | 重定向地址 https://teams.microsoft.com/ |
| grant_type | grant_type | string | authorization_code必须值 |
| client_secret | 应用程序密码 | string | 平台配置的证书和密码 |
| scope | 权限范围 | string | API权限名称,多个权限使用空格隔开 |
返回结果例
{
"token_type": "Bearer",
"scope": "Calendars.Read Calendars.ReadWrite openid profile User.Read email",
"expires_in": 3599,
"ext_expires_in": 3599,
"access_token": "eyJ0eXAiOiJKV1QiLCJub25jZSI6IkkwMmRVSlJRekRzUzk0RW5yR1NwYVRNZXJreldV....."
}
3. 获取人员日历
url: https://graph.microsoft.com/v1.0/me/calendars
请求方式:GET
请求参数
|
header参数
|
属性名
|
类型
|
备注
|
|---|---|---|---|
| Content-Type | Content-Type | string | application/json |
| Authorization | 权限 | string | Bearer+token 例(Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI6IkkwMmRVSlJRekRzUzk0RW5yR1NwYVRNZXJreldV.....) |
返回结果例
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('365fb7a0-6519-4200-81a3-77f5f481f3ee')/calendars",
"value": [
{
"id": "AAMkADIyMmM2ZGIwLTczNTUtNGJiNy1hMDFmLTExMzkyODM2ODcwZgBGAAAAAADRE_7hshIiTJYZD0pdc2brBwD1OXiPGRC2TYf8B7JVvb8uAAAAAAEGAAD1OXiPGRC2TYf8B7JVvb8uAAAAAE4DAAA=",
"name": "日历",
"color": "auto",
"changeKey": "9Tl4jxkQtk2H/AeyVb2/LgAAAAADJw==",
"canShare": true,
"canViewPrivateItems": true,
"canEdit": true,
"allowedOnlineMeetingProviders": [
"teamsForBusiness"
],
"defaultOnlineMeetingProvider": "teamsForBusiness",
"isTallyingResponses": true,
"isRemovable": false,
"owner": {
"name": "xxxxxx",
"address": "xxxx@gaiaworktest.onmicrosoft.com"
}
},
{
"id": "AAMkADIyMmM2ZGIwLTczNTUtNGJiNy1hMDFmLTExMzkyODM2ODcwZgBGAAAAAADRE_7hshIiTJYZD0pdc2brBwD1OXiPGRC2TYf8B7JVvb8uAAAAAAEGAAD1OXiPGRC2TYf8B7JVvb8uAAAAAE4EAAA=",
"name": "中国 节假日",
"color": "auto",
"changeKey": "9Tl4jxkQtk2H/AeyVb2/LgAAAAADMw==",
"canShare": false,
"canViewPrivateItems": true,
"canEdit": false,
"allowedOnlineMeetingProviders": [],
"defaultOnlineMeetingProvider": "unknown",
"isTallyingResponses": false,
"isRemovable": true,
"owner": {
"name": "xxxxx",
"address": "xxxxxx@gaiaworktest.onmicrosoft.com"
}
}
]
}
4. 创建日历
url: https://graph.microsoft.com/v1.0/me/calendars
请求方式:POST
请求参数 application/json
|
header参数
|
属性名
|
类型
|
备注
|
|---|---|---|---|
| Content-Type | Content-Type | string | application/json |
| Authorization | 权限 | string | Bearer+token 例(Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI6IkkwMmRVSlJRekRzUzk0RW5yR1NwYVRNZXJreldV.....) |
body实体
{
"name": "test1"
}
5. 创建日历事件
url: https://graph.microsoft.com/v1.0/me/events
请求方式:POST
请求参数 application/json
|
header参数
|
属性名
|
类型
|
备注
|
|---|---|---|---|
| Content-Type | Content-Type | string | application/json |
| Authorization | 权限 | string | Bearer+token 例(Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI6IkkwMmRVSlJRekRzUzk0RW5yR1NwYVRNZXJreldV.....) |
body实体
{
"subject": "Let's go for lunch",
"body": {
"contentType": "HTML",
"content": "postman添加"
},
"start": {
"dateTime": "2020-09-15T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2020-09-15T14:00:00",
"timeZone": "Pacific Standard Time"
},
"location":{
"displayName":"Harry's Bar"
},
"attendees": [
{
"emailAddress": {
"address":"xxxx@gaiaworktest.onmicrosoft.com",
"name": "xxxxx"
},
"type": "required"
}
],
"allowNewTimeProposals": true
}
浙公网安备 33010602011771号