我创建了一个C#控制台应用程序,用于从Office 365帐户获取本地存储的日历。
我在Azure中创建了一个Office 365开发人员帐户,检查了Azure AD中的目录并附加了在线屏幕截图。
运行代码时出现异常。我使用add connected服务添加API并登录Azure门户以更新门户中Office 365的所有权限。
我还在app.config中的Azure门户中添加了应用程序客户端ID,并验证了代码中的重定向URI和客户端ID值。由于使用的代码是连接服务添加的默认代码,因此我不包括代码
我做错了什么?
Microsoft.Office365.OAuth.AuthenticationFailedException:AADSTS90011:请求是
找到不明确的多个应用程序标识符。应用标识符:'3e
6a7297-508c-4696-9e1e-22474254a262,c6d9a502-fb34-42d8-ae10-d15787978dea'。
跟踪ID:41d4422e-73fd-48dd-bae1-54b5b098eb3d
相关ID:fa5a4c41-576c-46fe-99d0-85bc1afb442b
时间戳:2014-06-12 14:34:47Z ---> Microsoft.IdentityModel.Clients.ActiveDirec
tory.ActiveDirectoryAuthenticationException:AADSTS90011:请求不明确,
找到多个应用标识符。应用标识符:'3e6a7297-508c-
4696-9e1e-22474254a262,c6d9a502-fb34-42d8-ae10-d15787978dea'。
跟踪ID:41d4422e-73fd-48dd-bae1-54b5b098eb3d
相关ID:fa5a4c41-576c-46fe-99d0-85bc1afb442b
时间戳:2014-06-12 14:34:47Z ---> System.Net.WebException:远程服务器
返回错误:(400)错误请求。
在System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
在System.Threading.Tasks.TaskFactory 1.FromAsyncCoreLogic(IAsyncResult iar,
Func
2 endFunction,Action 1 endAction, Task
1 promise,Boolean requiresSynchron
化)
---从抛出异常的先前位置开始的堆栈跟踪结束---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()
at Microsoft.IdentityModel.Clients.ActiveDirectory.HttpHelper.<GetResponseSyn
cOrAsync>d__b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
在Microsoft.IdentityModel.Clients.ActiveDirectory.HttpHelper.d__0 1.MoveNext()
--- End of inner exception stack trace ---
at Microsoft.IdentityModel.Clients.ActiveDirectory.HttpHelper.<SendPostReques
tAndDeserializeJsonResponseAsync>d__0
1.MoveNext()
---从抛出异常的先前位置开始的堆栈跟踪结束---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()
at Microsoft.IdentityModel.Clients.ActiveDirectory.OAuth2Request.<SendHttpMes
sageAsync>d__f.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
在Microsoft.IdentityModel.Clients.ActiveDirectory.OAuth2Request.d__a.MoveNext()
---从抛出异常的先前位置开始的堆栈跟踪结束---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<Sen
dOAuth2RequestByRefreshTokenAsync>d__29.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
在Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.d__16.MoveNext()
---从抛出异常的先前位置开始的堆栈跟踪结束---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenByRefreshTokenAsync>d__59.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
在Microsoft.Office365.OAuth.Authenticator.d__11.MoveNext()
---内部异常堆栈跟踪结束---
在Microsoft.Office365.OAuth.Authenticator.d__11.MoveNext()
---从抛出异常的先前位置开始的堆栈跟踪结束---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()
at Microsoft.Office365.OAuth.RefreshToken.<GetAccessTokenAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
在Microsoft.Office365.Exchange.Extensions.DataServiceContextWrapper.d__1.MoveNext()
---从抛出异常的先前位置开始的堆栈跟踪结束---
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.GetResult()
在Microsoft.Office365.Exchange.Extensions.DataServiceContextWrapper.d__2d 2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
at myCal.Program.d__2.MoveNext()in c:\ vasu \ myCal \ myCal \ Program.cs:第23行
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Office365.Exchange;
using Microsoft.Office365.OAuth;
namespace ConsoleApp
{
class Program
{
const string ExchangeResourceId = "https://outlook.office365.com";
const string ExchangeServiceRoot = "https://outlook.office365.com/ews/odata";
public static async Task<IOrderedEnumerable<IEvent>> GetCalendarEvents()
{
try
{
var client = await EnsureClientCreated();
// Obtain calendar event data
var eventsResults = await (from i in client.Me.Events
where i.End >= DateTimeOffset.UtcNow
select i).Take(10).ExecuteAsync();
var events = eventsResults.CurrentPage.OrderBy(e => e.Start);
return events;
}
catch (Exception ex)
{
Console.WriteLine(ex);
return null;
}
}
private static async Task<ExchangeClient> EnsureClientCreated()
{
Authenticator authenticator = new Authenticator();
var authInfo = await authenticator.AuthenticateAsync(ExchangeResourceId);
return new ExchangeClient(new Uri(ExchangeServiceRoot), authInfo.GetAccessToken);
}
public static async Task SignOut()
{
await new Authenticator().LogoutAsync();
}
private static async Task<object> GetCal()
{
var x = await GetCalendarEvents();
return x;
}
static void Main(string[] args)
{
Console.WriteLine("Starts");
var x = GetCal();
Console.WriteLine("Press any key to close");
Console.Read();
}
}
}