简体   繁体   English

Microsoft Graph API-用户响应JSON不完整

[英]Microsoft Graph API - User response JSON not complete

The company I work for needs to develop an API that will export Office 365 contacts and import them into our user profile's contacts. 我工作的公司需要开发一个API,该API可以导出Office 365联系人并将其导入到我们的用户配置文件的联系人中。 This runs as some sort of daemon. 它作为某种守护程序运行。

I found Microsoft's Graph API and been working on it for days to get it running, but the GET contacts function doesn't seem to work for me. 我找到了Microsoft的Graph API,并为之运行了好几天以使其运行,但是GET contact函数似乎不适用于我。

I'm using the resource graph.microsoft.com and trying to get contacts with /users/{id}/contacts using PHP cURL. 我正在使用资源graph.microsoft.com并尝试使用PHP cURL与/users/{id}/contacts取得联系。

stdClass Object
(
    [error] => stdClass Object
        (
            [code] => ResourceNotFound
            [message] => Resource could not be discovered.
            [innerError] => stdClass Object
                (
                    [request-id] => 134b1964-9421-4fce-84ba-aca1525c705e
                    [date] => 2017-03-20T15:35:39
                )

        )

)

I'm getting an access token just fine (my app currently requests all read/write permissions to avoid being stuck because of missing privileges and they have been consented to by an admin account). 我正在获得访问令牌(我的应用程序当前请求所有读取/写入权限,以避免由于缺少权限而被卡住,并且已被管理员帐户同意)。

I've found out that the reason to this is probably because the User response JSON isn't completely formatted as it's supposed to be. 我发现这样做的原因可能是因为用户响应JSON的格式未达到预期的格式。 Microsoft's Documentation shows a full representation of the User resource. Microsoft的文档显示了用户资源的完整表示。 Mine seems to be missing all the relationships with other resources, like "contacts" that I need. 我的似乎缺少与其他资源的所有关系,例如我需要的“联系人”。 Here's the JSON I get from the Graph API using /users/{id} : 这是我使用/users/{id}从Graph API获得的JSON:

stdClass Object
(
    [@odata.context] => https://graph.microsoft.com/beta/$metadata#users(contacts)/$entity
    [id] => e4007399-90fb-489d-a0f8-2c577f219638
    [accountEnabled] => 1
    [assignedLicenses] => Array
        (
        )

    [assignedPlans] => Array
        (
        )

    [businessPhones] => Array
        (
        )

    [city] => 
    [companyName] => 
    [country] => 
    [department] => 
    [displayName] => Loic Didelot
    [givenName] => Loic
    [jobTitle] => 
    [mail] => 
    [mailNickname] => vendors_mixvoip.com#EXT#
    [mobilePhone] => 
    [onPremisesDomainName] => 
    [onPremisesImmutableId] => 
    [onPremisesLastSyncDateTime] => 
    [onPremisesSecurityIdentifier] => 
    [onPremisesSamAccountName] => 
    [onPremisesSyncEnabled] => 
    [onPremisesUserPrincipalName] => 
    [passwordPolicies] => 
    [passwordProfile] => 
    [officeLocation] => 
    [postalCode] => 
    [preferredLanguage] => 
    [provisionedPlans] => Array
        (
        )

    [proxyAddresses] => Array
        (
        )

    [refreshTokensValidFromDateTime] => 2017-03-14T09:13:10Z
    [showInAddressList] => 
    [imAddresses] => Array
        (
        )

    [state] => 
    [streetAddress] => 
    [surname] => Didelot
    [usageLocation] => 
    [userPrincipalName] => vendors_mixvoip.com#EXT#@vendorsmixvoip.onmicrosoft.com
    [userType] => Member
)

I haven't been able to find how to solve this, when I try searching for this problem, I get results for "custom properties" that can be selected by using /users/{id}?$select=customPropertyName . 我一直无法找到解决方法,当我尝试搜索此问题时,会得到“自定义属性”的结果,可以使用/users/{id}?$select=customPropertyName This doesn't work for /users/{id}?$select=contacts . 这不适用于/users/{id}?$select=contacts

Thanks in advance for your help. 在此先感谢您的帮助。

Microsoft Graph explorer is your friend (easy way to try out REST requests to the API): https://developer.microsoft.com/en-us/graph/graph-explorer Microsoft Graph Explorer是您的朋友(尝试对API进行REST请求的简便方法): https : //developer.microsoft.com/zh-cn/graph/graph-explorer

Also if you look at the front page of our documentation overview, there are some example queries (although contacts is not one of them) that'll give you some ideas: https://developer.microsoft.com/en-us/graph/docs 另外,如果您查看我们的文档概述的首页,还会有一些示例查询(尽管联系方式不是其中之一),这些示例将为您提供一些想法: https : //developer.microsoft.com/en-us/graph /文档

Anyway - the call you need to make is 无论如何-您需要拨打的电话是

GET https://graph.microsoft.com/v1.0/users/{id}/contacts

This returns the user/{id}'s set/collection of personal contacts. 这将返回用户/ {id}的个人联系人设置/集合。 The resource type (for the collection) is a contact and not a user . (用于集合的)资源类型是contact而不是user

For more information on contact resource type and List contacts see the following topics: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/contact https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_list_contacts 有关联系人资源类型和列表联系人的更多信息,请参见以下主题: https: //developer.microsoft.com/zh-cn/graph/docs/api-reference/v1.0/resources/contact https:// developer。 microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_list_contacts

Hope this helps, 希望这可以帮助,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM