[英]Sending message to Team chat using c# application system
目前我正在使用 Microsoft Graph API beta 的方式,您可以在聊天中發送消息來編寫應用程序,但我遇到這些錯誤找不到類型或名稱空間 ChatMessage ,名稱 authProvider 在當前上下文中不存在, await 運算符只能在 async 修飾符中使用,並將其返回類型更改為 tásk並且Microsoft.GraphGraphServiceClient 不包含 Chat 的定義,並且沒有可以找到接受 Microsoft.Graph.Graph.ServiceClient 類型的第一個參數的擴展方法 Chats . 誰能幫我解決它。
非常感謝。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Graph;
namespace w
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
GraphServiceClient graphClient = new GraphServiceClient(**authProvider**);
var chatMessage = new **ChatMessage**
{
Body = new ItemBody
{
Content = "Hello world"
}
};
*await* graphClient.**Chats**["19:056680e9-868a-49a2-bf96-2ba2d2c39b5d_76ff09a8-7650-426d-843b-3d1104128f25@unq.gbl.spaces"].Messages
.Request()
.AddAsync(chatMessage);
}
}
}
}
根據 文檔使用using Microsoft.Graph.Beta;
而不是using Microsoft.Graph;
.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Graph.Beta;
確實,我們最好不要使用測試版 api 但實際上這個 api有測試版,所以使用測試版應該不會導致異常。
根據您的錯誤信息, The name authProvider does not exist in the current context
,所以您似乎誤解了authProvider
中提到的authProvider。 有一個超鏈接。
關於authProvider
,即包含授權信息的 object 。 await* graphClient.**Chats**["19.....
is calling the ms graph api, and we need the access token in the request header to call the api right? But now since you are using the graph SDK,所以你只需要准備authProvider。
AuthProvider 是 Azure AD 中包含的東西,Azure AD 為您提供兩種流程,一種是用戶先登錄才能獲得授權,因此您必須在這種情況下提供一個登錄頁面,例如Authorization code provider
。 另一個用於應用程序,因此沒有用戶登錄,您必須創建一個 azure 廣告應用程序,然后獲取應用程序客戶端密碼以在您自己的代碼中驗證廣告應用程序,這稱為Client credentials provider
。 但是此 api 不支持Client credentials provider
。
因此,您可以按照本節創建 Auth 代碼提供程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.