我是Teams和Microsoft Graph的新手。
我的目标:从C#桌面应用程序向通道发送消息。
我认为我已经取得了一些进展,我获得了团队ID,渠道ID和客户ID。我从NuGet安装了Graph Beta软件包。
string clientId = "xxxSomeIDxxx";
IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
.Create(clientId)
.Build();
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var chatMessage = new ChatMessage
{
Subject = null,
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "<attachment id=\"74d20c7f34aa4a7fb74e2b30004247c5\"></attachment>"
},
Attachments = new List<ChatMessageAttachment>()
{
new ChatMessageAttachment
{
Id = "74d20c7f34aa4a7fb74e2b30004247c5",
ContentType = "application/vnd.microsoft.card.thumbnail",
ContentUrl = null,
Content = "Here is some body text.",
Name = null,
ThumbnailUrl = null
}
}
};
await graphClient.Teams["xxxSomeIDxxx"].Channels["xxSomeIdxxx"].Messages
.Request()
.AddAsync(chatMessage);
我不知道如何制作身份验证提供程序。
通过查看,看来这是正确的选择:
InteractiveAuthenticationProvider authProvider = new InteractiveAuthenticationProvider(publicClientApplication, scopes);
但是作用域是不确定的。
有人可以协助并告诉遇到哪个Microsoft Graph身份验证提供程序用于C#中的ChatMessage
我使用Visual Studio 2017 C#Windows窗体应用程序 微软团队
答案 0 :(得分:0)
接口 const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
const hero = new Image();
hero.src = '../img/hero.png';
let x = 430;
let y = 425;
hero.onload = function() {
ctx.drawImage(hero,x,y,31,86)
}
const go = document.querySelector('.go_university');
let tur = 0;
let timer;
let direction = 0;
go.addEventListener('click',()=>{
tur += 1;
turn();
})
function turn(){
ctx.clearRect(0,0,960,630);
direction+=1;
if(direction<=15){
x-=2;
y=(y-2/3);
}else if(direction >= 15 && direction <= 28){
x-=2;
y=(y-2);
}else if(direction >=28 && direction <=48){
x-=2;
y=(y+3/6);
}else if(direction >= 48 && direction <=70){
x-=2;
y=(y+3/6);
}
timer = setTimeout(turn,60);
ctx.drawImage(hero,x,y,31,86)
}
只有一个方法:
IAuthenticationProvider
我们使用一个简单的 AuthenticationProvider,如下所示:
Task AuthenticateRequestAsync(HttpRequestMessage request);
我们使用它来将我们的访问令牌保存在 MemoryCache 中,因为我们有一个调用 Graph API 的服务而不是特定用户。无论如何,我希望它可以提供一些指导:
public class AuthenticationProvider : IAuthenticationProvider
{
private readonly string _accessToken;
public AuthenticationProvider(string accessToken)
{
_accessToken = accessToken;
}
public Task AuthenticateRequestAsync(HttpRequestMessage request)
{
request.Headers.Add("Authorization", $"Bearer {_accessToken}");
return Task.CompletedTask;
}
}