如何从C#调用Microsoft Graph Beta API [英] How to call Microsoft Graph Beta API from C#

查看:63
本文介绍了如何从C#调用Microsoft Graph Beta API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取用户个人资料图片的内容,但发现我必须调用Beta版本,因为当前版本会显示以下错误消息:

I tried to get the content of the user's profile picture and I found out that I had to call the Beta version because the current version gives the following error message:

"code": "GetUserPhoto",
"message": "The operation is not supported."

所以,我试图切换到Beta,这是我用C#编写的代码,但没有用:

So, I tried to switch to Beta, and here is the code that I wrote in C# to do it, but it doesn't work:

Microsoft.Graph 1.6.2

Microsoft.Graph 1.6.2

List<QueryOption> options = new List<QueryOption>
{
    new QueryOption("$api-version", "beta")
};

var pictureStream = await graphClient.Me.Photo.Content.Request(options).GetAsync();

我收到了相同的错误消息.

I got the same error message.

我在Graph Explorer中尝试了相同的请求. 1.0无效,但Beta有效.

I tried the same request in the Graph Explorer. The 1.0 doesn't work, but Beta works.

推荐答案

Azure AD Graph API使用api-version查询参数.这是与Microsoft Graph不同的API.功能上有很多重叠(Azure AD Graph正在缓慢地迁移到Microsoft Graph),但是它们使用完全不同的实体和调用约定.

The api-version query parameter is used by the Azure AD Graph API. This is a different API than Microsoft Graph. There is a lot of functional overlap (Azure AD Graph is slowly being migrated over to Microsoft Graph) but they use entirely different entities and calling conventions.

为了使用 Microsoft Graph .NET客户端库/beta终结点,您需要更改客户端的BaseUrl:

In order to call the /beta endpoint using the Microsoft Graph .NET Client Library, you need to change the BaseUrl of the client:

graphClient.BaseUrl = "https://graph.microsoft.com/beta";
var pictureStream = await graphClient.Me.Photo.Content.Request().GetAsync();

关于/beta端点的一些重要说明:

Some important notes about the /beta endpoint:

  1. 不支持,不适合生产.所以不要那样做.或者至少不要告诉任何人,如果停止工作,也不要致电支持部门. ;-)

  1. It isn't supported and isn't suitable for production. So don't do that. Or at least don't tell anyone and don't call Support if it stops working. ;-)

.NET客户端使用基于生产元数据构造的对象.这意味着在/beta中添加的任何实体,动作或属性在SDK随附的模型中都不存在.

The .NET Client uses objects constructed off the production metadata. This means that any entities, actions or properties that were added in /beta don't exist in the models shipped with the SDK.

.NET客户端将忽略Microsoft Graph不希望看到的任何值.因此,如果端点返回的属性未包含在生产元数据中(请参阅#2),则它将被忽略.

The .NET Client will ignore any values returned by Microsoft Graph that it doesn't expect to see. So if an endpoint returns a property that wasn't included in the production metadata (see #2), it will simply be ignored.

只要您仅使用/beta来获得功能,但仍希望获得/v1.0结果,它就可以正常工作.例如,照片仅在v1.0中查看Exchange,但同时查看Exchange Active Directory,但仍返回相同的结果.从理论上讲,这意味着您可以毫无问题地将/beta交换为/v1.0.

So long as you're only using a /beta to gain functionality but still expecting /v1.0 results, it should work okay. Photos for example only look at Exchange in v1.0 but look in both Exchange and Active Directory but still return the same result. In theory this means you should be able to swap /beta for /v1.0 without a problem.

这篇关于如何从C#调用Microsoft Graph Beta API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆