- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Microsoft Graph API 访问电子邮件。当我尝试访问电子邮件时,出现以下错误。
Microsoft.Graph.ServiceException: 'Code: OrganizationFromTenantGuidNotFound
Message: The tenant for tenant guid '<some id>' does not exist.
这是获取电子邮件的代码
var graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
return Task.CompletedTask;
}));
var userId = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfcecad6dcd4ccd6d3c9dacddcd0d1d1dadccbffd0cacbd3d0d0d491dcd0d2" rel="noreferrer noopener nofollow">[email protected]</a>"; // Tried <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="34425d5e554d5a5d465955587445415d575f475d58425146575b5a5a5157405b4140585b5b5f1a5b5a595d57465b475b52401a575b59" rel="noreferrer noopener nofollow">[email protected]</a> also
var messageId = "Actual message id";
var email = await graphServiceClient.Users[userId].Messages[messageId].Request().GetAsync();
这是获取访问 token 的代码
private const string _clientId = "xxxxxxx-xxxxxx-xxxxxxx-xxxx";
private const string _clientSecret = "xxxxxxx-xxxxxx-xxxxxxx-xxxx";
private const string _tenantName = "ecd90453-34b6-xxxx-xxxx-xxxxxxxxx";
private readonly string _uri = $"https://login.microsoftonline.com/{_tenantName}/oauth2/v2.0/token";
private const string _grantType = "client_credentials";
private const string _scope = "https://graph.microsoft.com/.default";
public async Task<string> GetAccessTokenAsync()
{
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("Grant_Type", _grantType),
new KeyValuePair<string, string>("Scope", _scope),
new KeyValuePair<string, string>("Client_Id", _clientId),
new KeyValuePair<string, string>("Client_Secret", _clientSecret)
});
var responce = await _httpClient.PostAsync(_uri, content);
responce.EnsureSuccessStatusCode();
var jsonString = await responce.Content.ReadAsStringAsync();
var document = await JsonDocument.ParseAsync(jsonString.ToStream());
return document.RootElement.GetProperty("access_token").GetString();
}
我在网上搜索了解决方案。我找到了一些解决方案,但没有一个对我有用。
用户类型必须是成员(member)。我的用户类型已经是成员(member)。原始问题 - “The tenant for tenant guid does not exist” even though user is listed on users endpoint?
使用域作为tenentId。它不起作用。原始问题 - Getting "The tenant for tenant guid '' does not exist"
private const string _tenantName = "quicksilverconnectoutlook.onmicrosoft.com";
一些有趣的观察
我能够获取用户,但无法获取他们的邮件。注意:在下面的代码中,只有用户 ID 起作用,而电子邮件 ID 不起作用。
var userId = "8685e56b-b1a8-45cf-a5d1-5c5ddadd0f3e";
// EmailId (<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6312160a0008100a0f150611000c0d0d060017230c16170f0c0c084d000c0e" rel="noreferrer noopener nofollow">[email protected]</a>) is not working here
var user = await graphServiceClient.Users[userId].Request().GetAsync();
我发现如果我使用 Graph Explorer 生成的访问 token 那么我的代码就可以正常工作了。所以问题可能出在我的 GetAccessTokenAsync
代码或其配置详细信息中。
更新:
我想使用应用程序权限而不是委派权限,因为我的应用程序将使用通知订阅在任何用户收到新邮件时获取通知。另外,我想获取新邮件的完整电子邮件详细信息。简而言之,该应用程序将在后台运行。
var graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
return Task.CompletedTask;
}));
var subscription = await graphServiceClient.Subscriptions.Request().AddAsync(new Subscription()
{
Resource = "/users/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="deafabb7bdb5adb7b2a8bbacbdb1b0b0bbbdaa9eb1abaab2b1b1b5f0bdb1b3" rel="noreferrer noopener nofollow">[email protected]</a>/messages",
ChangeType = "created",
ExpirationDateTime = DateTimeOffset.Now.AddDays(3).AddHours(-1),
NotificationUrl = "https://asdasdasd.azurewebsites.net/Outlook/NewMailListener",
ClientState = Guid.NewGuid().ToString()
});
最佳答案
问题似乎是由于您没有 O365 订阅引起的。尽管您有 Azure 订阅并且有 Azure 帐户的电子邮件,但您没有 O365 订阅。所以你只能通过图表获取用户,但不能通过图表获取电子邮件。
这个问题,你可以直接看这个page (使用您的azure管理员帐户登录)并购买O365订阅。(例如:Office 65 E3
)
也许您还可以在同一页面上购买 Exchange Online(例如 Exchange Online(计划 2)
)来访问电子邮件。
顺便说一句,您的代码中有一个错误。您使用 client_credentials
作为“Grant_Type”并使用 DelegateAuthenticationProvider
。如果您想使用DelegateAuthenticationProvider
,则需要将“Grant_Type”设置为password
,而不是client_credentials
。
要使用客户端凭据身份验证,您需要安装Microsoft.Graph.Auth 。注意:这是一个预发行包。这是一个代码片段
var confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(configuration.ClientId)
.WithTenantId(configuration.TenantId)
.WithClientSecret(configuration.ClientSecret)
.Build();
var authProvider = new ClientCredentialProvider(confidentialClientApplication);
var graphServiceClient = new GraphServiceClient(_clientCredentialProviderauthProvider);
关于c# - 使用 Graph API 时出现 "The tenant for tenant guid does not exist"- 用户类型为成员(member)的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63646335/
我有某些场景(例如,一个自定义类来保存 Sql 参数),其中可能需要也可能不需要变量。传统上,我一直将这些定义为 Guid? 类型,并在使用前使用 myGuid.HasValue 检查有效值。 当然在
在 rpc.h 中,GUID 结构声明如下: typedef struct _GUID { DWORD Data1; WORD Data2; WORD Data3; B
使用 Dynamics CRM 我试图创建一个实体的实例。我想手动设置 GUID,但如果我拥有作为 DynamicEntity 主键的属性,则会出现以下错误。 Service could not pr
我需要将 GUID PK 字段(长度 = 36)发送到只接受 20 个字符长的下游系统。在下游系统中增加字段的长度成本过高。如果我截断该字段,那么我将失去它的唯一性。 有什么方法可以在不丢失唯一性的情
我听说 melissa 蠕虫的创建者因生成的 GUID 可以链接回他使用的计算机的 MAC 地址而被定罪。 做到这一点有多难?除了 GUID,他们还需要哪些数据?喜欢 MAC 地址本身还是创建时间?
使用 GUID 作为文件名和 นด 上传的图像以避免重复有什么缺点吗? 最佳答案 您的文件名将是唯一的,真的。但是没有任何方法可以按任何顺序对它们进行排序。 您可以使用 Unix TimeStamp在
我正在做一些互操作,需要传递一些 GUID。有没有办法将 GUID 属性添加到枚举值,并且当它被编码时它具有适当的值? 基本上我正在尝试转换代码 #if !defined( STATIC_KSDATA
我有一个文件,其中包含大量出现的字符串 Guid="GUID HERE" (其中 GUID HERE 在每次出现时都是唯一的 GUID),我想用新的唯一 GUID 替换每个现有的 GUID。 这是在
我已经向我们的客户发送了 10000 封邮件,每封邮件都有一个格式的链接 http://example.com/LogIn?key={guid} 不幸的是guid我发送的是随机 guids(由 Gui
使用 Breeze,在创建实体时填充 GUID 键的最简单方法是什么? 最佳答案 我假设您的实体已配置为客户端负责为新实体设置 Guid 键。这是 Entity Framework 代码优先实体的 G
我看到这两个首字母缩略词被抛出,我想知道 GUID 和 UUID 之间是否有任何区别? 最佳答案 简单回答是:**没有区别,它们是同一个东西。 2020-08-20 更新 :虽然 GUID(由 Mic
我注意到有些人不打算使用通常的递增数字作为 ID,而是简单地生成 GUID。优点包括: 快速简单 无需跟踪以前的 ID 即使在机器之间互不了解的情况下也能保证唯一性 一些缺点是: 可能存在性能瓶颈 使
我是 C++/CLI 的新手,我正在尝试将 native C++ GUID 转换为我的 C++/CLI Guid^。尝试转换时: BlockInfo^ blockInfo = gcnew BlockI
这个问题在这里已经有了答案: 11 年前关闭。 Possible Duplicate: Is there any difference between a GUID and a UUID? GUID
我正在使用 Data::GUID生成 GUID。然而,每当我在同一个“ session ”中生成 GUID,即运行脚本时,唯一改变的数字是最前面的数字: 3BAF1240-0573-11E4-B31C
我有一个对象列表,它们具有 id 的 guid。我想使用这个对象列表中的 id 创建一个 guid,我可以使用它来确保列表没有改变。如果删除/添加了一个对象,则 guid 会有所不同。我想到的是使用哈
上下文:ASP.NET Web API v2 给定一个类似于这个的 URL: http://localhost/something?id=cbc66d32-ece8-400f-a574-e36b911
这是将 Guid 转换为 Guid 的惯用方法吗?? new Guid?(new Guid(myString)); 最佳答案 不,这是: Guid? foo = new Guid(myString);
我想从输入字符串生成一个 GUID。假设我从用户那里收到了 guid,它是 81a130d2-502f-4cf1-a376-63edeb000e9f 所以我可以这样做: Guid g = Guid.
为什么无参数 Guid 构造函数生成一个空 GUID,而不是像 Guid.NewGuid() 那样默认生成一个? 空 Guid 是否有特殊用途? 最佳答案 Why does the parameter
我是一名优秀的程序员,十分优秀!