Microsoft graph api 在Microsoft Team Channel中以消息形式从本地系统发送文件/图像
如何使用Microsoft Graph API的发送消息在Microsoft Team频道中发送本地文件/图像 在创建发送团队频道的消息时,我跟随文档附上了一个图像。我正在尝试发送base64格式的图像。但是我犯了一个错误Microsoft graph api 在Microsoft Team Channel中以消息形式从本地系统发送文件/图像,microsoft-graph-api,microsoft-teams,Microsoft Graph Api,Microsoft Teams,如何使用Microsoft Graph API的发送消息在Microsoft Team频道中发送本地文件/图像 在创建发送团队频道的消息时,我跟随文档附上了一个图像。我正在尝试发送base64格式的图像。但是我犯了一个错误 { "error": { "code": "InternalServerError", "message": "Failed to process
{
"error": {
"code": "InternalServerError",
"message": "Failed to process request.",
"innerError": {
"date": "2020-09-25T11:43:02",
"request-id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"client-request-id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
}
}
似乎没有合适的API让您直接将本地文件作为消息发送 仅支持发送已在SharePoint中保存的文件。因此,发送本地文件有两个步骤:首先,将文件上载到SharePoint,然后创建聊天信息
1。将文件上载到SharePoint:
POST https://graph.microsoft.com/v1.0/teams/{id}/channels/{id}/messages
Content-type: application/json
{
"body": {
"contentType": "html",
"content": "Here's the latest budget. <attachment id=\"153fa47d-18c9-4179-be08-9879815a9f90\"></attachment>"
},
"attachments": [
{
"id": "153fa47d-18c9-4179-be08-9879815a9f90",
"contentType": "reference",
"contentUrl": "https://m365x987948.sharepoint.com/sites/test/Shared%20Documents/General/test%20doc.docx",
"name": "Budget.docx"
}
]
}
小于4MB的文件:
PUT https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/content
Header:
"Authorization" : "Bearer <access-token>"
Body: binary (select binary option in body in postman)
Upload a file using select file option
file-name: is file name along with extension example: test.txt
GET: https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/createUploadSession
Header:
"Authorization" : "Bearer <access-token>"
PUThttps://graph.microsoft.com/v1.0/drives/{{drive id}}/items/root:/{{{file name}}:/content
标题:
“授权”:“持票人”
2.创建聊天信息:
POST https://graph.microsoft.com/v1.0/teams/{id}/channels/{id}/messages
Content-type: application/json
{
"body": {
"contentType": "html",
"content": "Here's the latest budget. <attachment id=\"153fa47d-18c9-4179-be08-9879815a9f90\"></attachment>"
},
"attachments": [
{
"id": "153fa47d-18c9-4179-be08-9879815a9f90",
"contentType": "reference",
"contentUrl": "https://m365x987948.sharepoint.com/sites/test/Shared%20Documents/General/test%20doc.docx",
"name": "Budget.docx"
}
]
}
POSThttps://graph.microsoft.com/v1.0/teams/{id}/channels/{id}/messages
内容类型:application/json
{
“正文”:{
“内容类型”:“html”,
“内容”:“这是最新的预算。”
},
“附件”:[
{
“id”:“153fa47d-18c9-4179-be08-9879815a9f90”,
“内容类型”:“引用”,
“contentUrl”:”https://m365x987948.sharepoint.com/sites/test/Shared%20Documents/General/test%20doc.docx",
“名称”:“Budget.docx”
}
]
}
似乎没有合适的API可供您直接将本地文件作为消息发送
只支持发送已经在SharePoint中的文件。因此,有两个步骤可以发送本地文件:首先,将文件上载到SharePoint,然后创建chatMessage
1.将文件上载到SharePoint:
POST https://graph.microsoft.com/v1.0/teams/{id}/channels/{id}/messages
Content-type: application/json
{
"body": {
"contentType": "html",
"content": "Here's the latest budget. <attachment id=\"153fa47d-18c9-4179-be08-9879815a9f90\"></attachment>"
},
"attachments": [
{
"id": "153fa47d-18c9-4179-be08-9879815a9f90",
"contentType": "reference",
"contentUrl": "https://m365x987948.sharepoint.com/sites/test/Shared%20Documents/General/test%20doc.docx",
"name": "Budget.docx"
}
]
}
小于4MB的文件:
PUT https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/content
Header:
"Authorization" : "Bearer <access-token>"
Body: binary (select binary option in body in postman)
Upload a file using select file option
file-name: is file name along with extension example: test.txt
GET: https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/createUploadSession
Header:
"Authorization" : "Bearer <access-token>"
PUThttps://graph.microsoft.com/v1.0/drives/{{drive id}}/items/root:/{{{file name}}:/content
标题:
“授权”:“持票人”
2。创建聊天室消息:
POST https://graph.microsoft.com/v1.0/teams/{id}/channels/{id}/messages
Content-type: application/json
{
"body": {
"contentType": "html",
"content": "Here's the latest budget. <attachment id=\"153fa47d-18c9-4179-be08-9879815a9f90\"></attachment>"
},
"attachments": [
{
"id": "153fa47d-18c9-4179-be08-9879815a9f90",
"contentType": "reference",
"contentUrl": "https://m365x987948.sharepoint.com/sites/test/Shared%20Documents/General/test%20doc.docx",
"name": "Budget.docx"
}
]
}
POSThttps://graph.microsoft.com/v1.0/teams/{id}/channels/{id}/messages
内容类型:application/json
{
“正文”:{
“内容类型”:“html”,
“内容”:“这是最新的预算。”
},
“附件”:[
{
“id”:“153fa47d-18c9-4179-be08-9879815a9f90”,
“内容类型”:“引用”,
“contentUrl”:”https://m365x987948.sharepoint.com/sites/test/Shared%20Documents/General/test%20doc.docx",
“名称”:“Budget.docx”
}
]
}
您可以使用graph API发送文件附件。你能检查一下这个吗?@Nikitha msft谢谢。它适合我。你可以使用图形API发送文件附件。你能检查一下这个吗?@Nikitha msft谢谢。它对我有用。