从MS Graph API获取联系人时找不到资源 [英] Resource Not Found While fetching contacts from MS Graph API

查看:109
本文介绍了从MS Graph API获取联系人时找不到资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在github示例下面尝试了Azure AD身份验证,并成功获取了具有正确回调URL的访问令牌.

I tried below github sample for Azure AD Authentication and successfully getting access token with proper call back URL.

https://github.com/Microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/18.bot-authentication

根据在 https://apps.dev.microsoft中创建的应用程序修改和配置的Web.config密钥. com

  <add key="ActiveDirectory.Mode" value="v1" />
<add key="ActiveDirectory.ResourceId" value="https://graph.microsoft.com" />
<add key="ActiveDirectory.EndpointUrl" value="https://login.microsoftonline.com" />
<add key="ActiveDirectory.Tenant" value="xyz-xyz" />
<add key="ActiveDirectory.ClientId" value="xyz-xyz" />
<add key="ActiveDirectory.ClientSecret" value="xyz-xyz" />
 <add key="ActiveDirectory.RedirectUrl" value="http://localhost:3979/api/Callback" />
<add key="ActiveDirectory.Scopes" value="Calendars.Read,Calendars.ReadWrite,Contacts.Read,Contacts.ReadWrite,Mail.Read,Mail.ReadWrite,User.Read" />

我已经越过收到了 jwt.ms 的检查访问令牌.这是一个有效令牌,其作用域定义与我在web.config中定义的完全相同.

I had crossed checked access token that i received jwt.ms. It is a valid token with scopes defined exactly as i defined in web.config.

我可以通过传递令牌来从API获取用户个人资料数据,但是在尝试调用用户的联系人"时,却遇到了错误.

I am able to get User Profile data from API by passing token but while trying to call "Contacts" of user, I am getting below error.

{
"error": {
    "code": "ResourceNotFound",
    "message": "Resource could not be discovered.",
    "innerError": {
        "request-id": "6f0f3ec9-76c9-4662-ac25-0bc73f887268",
        "date": "2019-03-02T17:23:35"
    }
}

}

代码调用联系人API调用.

Code calling Contact API call.

   //Get Logged in user contacts
    public async Task<IUserContactsCollectionPage> GetMyContactsAsync()
    {
        var graphClient = GetAuthenticatedClient();
        IUserContactsCollectionPage contacts = await graphClient.Me.Contacts.Request().GetAsync();
        return contacts;
    }

仅供参考:在模拟器中显示登录卡授权示例URL如下所示

FYI: Displayed Sign In card in emulator Authorize sample URL is like below

https://login.microsoftonline.com/a76b43b0-3088-4c56-ba0d-01f317b1f18c/oauth2/authorize?resource=https:%2F%2Fgraph.microsoft.com&client_id=XYZ&response_type=code&haschrome=1&redirect_uri=http:%2F%2Flocalhost:3979%2Fapi%2FCallback&x-client-SKU=PCL.Desktop&x-client-Ver=3.13.9.1126&x-client-CPU=x64&x-client-OS=Microsoft+Windows+NT+10.0.16299.0&state=<stateID>

推荐答案

它可能由于多种原因而发生,这是很常见的问题之一,即要求您的注册应用程序具有授予权限.确保已按照相应的步骤进行操作.

It might happens for many reason one of the very common issue is to required grant permission to your registered app. Make sure you have done following steps accordingly.

登录到门户,然后在应用程序注册下选择您的应用程序. 然后单击设置,看到以下屏幕截图:

Login in to your portal and select your application under app registrations. Then click on settings see the screen shot below:

单击设置"后,将出现在右侧的新窗口中,单击必需的权限"菜单:请参见以下屏幕截图:

Once you clicked Settings new window will come up right side, click on Required Permission menu: see the screen shot below:

选择必需的权限"菜单,然后单击添加"按钮分配权限 参见下面的快照:

Select Required Permission Menu and assign your permission by clicking on Add button see the snap below:

点击选择API选项,如下所示:

Click on Select an API option see below:

选择所需的API并选中您要访问的API.完成权限后,单击完成".完成此步骤后,您可以从应用程序访问所需的资源/范围.希望对您有所帮助.谢谢. 看到下面的屏幕截图:

Select your desired API and checked it which you are like to access for. Once finished the permission click on Done. After this step you can access your required resource / Scope from your application. Hope it will be helpful for you.Thank You. see the screen shot below:

这篇关于从MS Graph API获取联系人时找不到资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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