azure MS图形API -从C#获取Pstn调用

flseospp  于 2023-01-27  发布在  C#
关注(0)|答案(1)|浏览(150)

我在弄清楚如何在C#中从MS Graph调用getPstnCalls时遇到了麻烦。我目前使用的是Graph的最新版本Microsoft Graph 4.51.0。根据documentation,调用getPstnCalls和调用get callRecord的方式与C#中的相同。

var callRecord = await graphClient.Communications.CallRecords["{callRecords.callRecord-id}"]
    .Request().GetAsync();

看起来好像有几个人要求更新文档;有些可以追溯到2020年,当时getPstnCalls还在测试阶段。
我以为会是这样的:

var pstnCallLogRows = await graphClient.Communications.CallRecords.GetPstnCalls
    .Request().GetAsync();

请注意,基于,我期望的数据类型与文档中的完全不同。(List<pstnCallLogRow>而不是callRecord
有人知道如何在C#中调用这个函数吗?

esyap4oy

esyap4oy1#

SDK 4.51不支持getPstnCalls,但pstnCallLogRow资源类型有一个模型PstnCallLogRow
您至少可以尝试创建一个HTTP请求并反序列化响应对象。

var requestUrl = client
     .Communications
     .CallRecords
     .AppendSegmentToRequestUrl("getPstnCalls(fromDateTime=2023-01-18T06:00:00Z,toDateTime=2023-01-24T07:00:00Z)");

// create GET request message
var hrm = new HttpRequestMessage(HttpMethod.Get, requestUrl);

// authenticate request message
await client.AuthenticationProvider.AuthenticateRequestAsync(hrm);

// send the request
var response = await client.HttpProvider.SendAsync(hrm);
if (response.IsSuccessStatusCode)
{
    // read response json string - it should be a collection of pstnCallLogRow
    var responseString = await response.Content.ReadAsStringAsync();

    // deserialize to a collection of PstnCallLogRow
    var logRows = client.HttpProvider.Serializer.DeserializeObject<List<PstnCallLogRow>>(responseString);
}
else
{
    throw new ServiceException(
                    new Error
                    {
                        Code = response.StatusCode.ToString(),
                        Message = await response.Content.ReadAsStringAsync()
                    });
}

相关问题