Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 仅应用令牌获取用户,但可以';不创建订阅?_Asp.net Core_Asp.net Core Mvc_Microsoft Graph Api - Fatal编程技术网

Asp.net core 仅应用令牌获取用户,但可以';不创建订阅?

Asp.net core 仅应用令牌获取用户,但可以';不创建订阅?,asp.net-core,asp.net-core-mvc,microsoft-graph-api,Asp.net Core,Asp.net Core Mvc,Microsoft Graph Api,我正在使用一个“仅应用程序”令牌来检索我的用户,这很好 一旦应用程序在用户中循环,它应该创建一个订阅,如下所示 但是,当尝试创建订阅时,请求仅返回: 代码:InvalidRequest消息:无法连接到远程服务器 内部误差 我的问题是,当我显然能够在检索用户的第一个请求中成功连接时,为什么订阅请求无法连接 我怎样才能看到内部错误 string tenantId = appSettings.TenantId; var client = sdkHelper.GetAuthenticatedClien

我正在使用一个“仅应用程序”令牌来检索我的用户,这很好

一旦应用程序在用户中循环,它应该创建一个订阅,如下所示

但是,当尝试创建订阅时,请求仅返回:

代码:InvalidRequest消息:无法连接到远程服务器

内部误差

我的问题是,当我显然能够在检索用户的第一个请求中成功连接时,为什么订阅请求无法连接

我怎样才能看到内部错误

string tenantId = appSettings.TenantId;

var client = sdkHelper.GetAuthenticatedClientAppOnly(tenantId);

// this request works...
IGraphServiceUsersCollectionPage users = await client.Users.Request().Filter("userPrincipalName eq 'MY_USER_PRINCIPAL_NAME'").GetAsync();

if (users?.Count > 0)
{
    foreach (User user in users)
    {
        // this request doesn't work...
        Subscription newSubscription = new Subscription();
        string clientState = Guid.NewGuid().ToString();
        newSubscription = await client.Subscriptions.Request().AddAsync(new Subscription
        {
            Resource = $"users/{ user.Id }@{ tenantId }/mailFolders('Inbox')/messages",
            //Resource = $"users/{ user.UserPrincipalName }/mailFolders('Inbox')/messages", // also tried using email address
            ChangeType = "created",
            NotificationUrl = "https://localhost:44334/notification/listen",
            ClientState = clientState,
            //ExpirationDateTime = DateTime.UtcNow + new TimeSpan(0, 0, 4230, 0) // current maximum lifespan for messages
            ExpirationDateTime = DateTime.UtcNow + new TimeSpan(0, 0, 15, 0)     // shorter duration useful for testing
        });
    }
}
当我将调用包装为try/catch时,错误消息如下,没有内部异常:

引发了类型为“Microsoft.Graph.ServiceException”的异常

我尝试了所有三个资源URL,但都产生了如上所示的相同错误:

  • Resource=
    $“users/{user.Id}/mailFolders('Inbox')/messages”,
  • Resource=
    $“users/{user.Id}@{tenantId}/mailFolders('Inbox')/messages”,
  • Resource=
    $“users/{user.UserPrincipalName}/mailFolders('Inbox')/messages”,
我在github上找到了这个线程,但是请求似乎对我不起作用

  • 仅允许应用程序请求创建订阅-
  • NotificationUrl不能是“localhost!”请求是从远程服务器发送的,因此它不知道本地主机是什么,因此失败。如果我将我的项目部署到远程服务器并传递URL,它可能会工作。我会试试