我有一個(gè)可以訪問(wèn)我的郵箱的應(yīng)用程序。我按照本教程創(chuàng)建了應(yīng)用程序:https://docs.microsoft.com/en-us/graph/tutorials/aspnet?tutorial-step=1然后我調(diào)整了應(yīng)用程序來(lái)閱讀郵件。這適用于我自己的郵件。但是,我需要訪問(wèn)一個(gè)共享收件箱,我可以訪問(wèn)該收件箱并且可以在我的 Outlook 中閱讀電子郵件。我嘗試使用以下代碼執(zhí)行此操作:public static async Task<IEnumerable<Message>> GetMailAsync() { var graphClient = GetAuthenticatedClient(); var mail = await graphClient.Users["usersemail@somewhere.com"].MailFolders.Inbox.Messages.Request() .GetAsync(); return mail; }但是,我收到一個(gè)未經(jīng)授權(quán)的錯(cuò)誤:授權(quán)錯(cuò)誤 這是我的授權(quán)碼:private static GraphServiceClient GetAuthenticatedClient() { return new GraphServiceClient( new DelegateAuthenticationProvider( async (requestMessage) => { // Get the signed in user's id and create a token cache string signedInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; HttpContextWrapper httpContext = new HttpContextWrapper(HttpContext.Current); TokenCache tokenStore = new SessionTokenStore(signedInUserId, httpContext).GetMsalCacheInstance(); var idClient = new ConfidentialClientApplication( appId, redirectUri, new ClientCredential(appSecret), tokenStore, null); })); }我在應(yīng)用程序中添加了權(quán)限應(yīng)用程序權(quán)限的圖像誰(shuí)能發(fā)現(xiàn)我在這里做錯(cuò)了什么?有些帖子認(rèn)為它不能以這種方式完成(Microsoft Graph API .NET 無(wú)法讀取共享郵件,Microsoft Graph API SDK .NET 問(wèn)題獲取其他用戶的電子郵件),但我可以讓它在圖形資源管理器中工作。任何幫助表示贊賞,包括關(guān)于如何改進(jìn)我的問(wèn)題的建議。
1 回答

慕俠2389804
TA貢獻(xiàn)1719條經(jīng)驗(yàn) 獲得超6個(gè)贊
發(fā)現(xiàn)問(wèn)題,我沒(méi)有正確設(shè)置appSettings。
我將“User.Read Mail.Read.Shared”添加到我的 PrivateSettings.Config 中,如下所示:
<add key="ida:AppScopes" value="User.Read Calendars.Read" />
<add key="ida:AppScopes" value="User.Read Mail.Read" />
<add key="ida:AppScopes" value="User.Read Mail.Read.Shared" />
希望這可以幫助某人。
- 1 回答
- 0 關(guān)注
- 180 瀏覽
添加回答
舉報(bào)
0/150
提交
取消