访问 API 响应中的所有数据
Accessing all data in API response
我目前正在使用 SDK 检索群组的详细信息。再看Group模型,显示数据的方法还是挺多的。
当我 print_r()
组时,它 returns 一个带有受保护的 _propDict 属性 的组对象。问题是,其中一些无法通过 getter 访问,例如:
Microsoft\Graph\Model\Group Object
(
[_propDict:protected] => Array
(
[id] => XX-YY-ZZ
[deletedDateTime] =>
[classification] =>
[createdDateTime] => 2019-04-18T15:09:57Z
[creationOptions] => Array
(
[0] => Team
[1] => classAssignments
[2] => ExchangeProvisioningFlags:2509
)
[description] =>
[displayName] => Example Group
[groupTypes] => Array
(
[0] => Unified
)
[mail] => test@example.com
[mailEnabled] => 1
[mailNickname] => ExampleGroup
[onPremisesLastSyncDateTime] =>
[onPremisesSecurityIdentifier] =>
[onPremisesSyncEnabled] =>
[preferredDataLocation] =>
[proxyAddresses] => Array
(
[0] => SPO:SPO_ABCDE123456
[1] => SMTP:test@example.com
[2] => smtp:rest@example.onmicrosoft.com
)
[renewedDateTime] => 2019-04-18T15:09:57Z
[resourceBehaviorOptions] => Array
(
[0] => HideGroupInOutlook
[1] => WelcomeEmailDisabled
[2] => ConnectorsDisabled
[3] => SubscribeNewGroupMembers
)
[resourceProvisioningOptions] => Array
(
[0] => Team
)
[securityEnabled] =>
[visibility] => HiddenMembership
[extension_ABC123_Education_ObjectType] => Section
[onPremisesProvisioningErrors] => Array
(
)
)
)
因此,例如,当前没有获取 deletedDateTime
或 createdDateTime
的方法。我也想获得 extension_ABC123_Education_ObjectType
值。
是否有使用组模型执行此操作的简单方法?
谢谢
The issue is, some of these aren't accessible via getters
确实,在这种情况下,可以考虑使用以下方法通过 msgraph-sdk-php
.
检索它
假设扩展数据按组公开并命名为 contoso_grpstatus
:
GET https://graph.microsoft.com/v1.0/groups/{group-id}?$select=displayName,description,contoso_grpstatus
{
"displayName": "Group 123",
"description": "Group 123",
"contoso_grpstatus": {
"@odata.type": "#microsoft.graph.ComplexExtensionValue",
"Status": "Active"
}
}
其中 contoso_grpstatus
是 schema extension
{
"id": "contoso_grpstatus",
"description": "Contoso - Group status",
"targetTypes": [
"Group"
],
"status": "Available",
"owner": "d1433ee1-b39b-49b0-b022-b1072a0aee38",
"properties": [
{
"name": "Status",
"type": "String"
}
]
}
然后可以引入扩展 \Microsoft\Graph\Model\Group
的自定义组 class:
class GroupWithStatus extends \Microsoft\Graph\Model\Group{
public function getStatus()
{
if (array_key_exists("contoso_grpstatus", $this->_propDict)) {
return $this->_propDict["contoso_grpstatus"];
} else {
return null;
}
}
}
最后可以像这样检索组属性 (DisplayName
) 以及自定义数据 (contoso_grpstatus
):
$url = "/groups/$groupId?$select=displayName,contoso_grpstatus";
$group = $client->createRequest("GET", $url)
->setReturnType(GroupWithStatus::class)
->execute();
$displayName = $group->getDisplayName();
$status = $group->getStatus(); //custom data property
我目前正在使用 SDK 检索群组的详细信息。再看Group模型,显示数据的方法还是挺多的。
当我 print_r()
组时,它 returns 一个带有受保护的 _propDict 属性 的组对象。问题是,其中一些无法通过 getter 访问,例如:
Microsoft\Graph\Model\Group Object
(
[_propDict:protected] => Array
(
[id] => XX-YY-ZZ
[deletedDateTime] =>
[classification] =>
[createdDateTime] => 2019-04-18T15:09:57Z
[creationOptions] => Array
(
[0] => Team
[1] => classAssignments
[2] => ExchangeProvisioningFlags:2509
)
[description] =>
[displayName] => Example Group
[groupTypes] => Array
(
[0] => Unified
)
[mail] => test@example.com
[mailEnabled] => 1
[mailNickname] => ExampleGroup
[onPremisesLastSyncDateTime] =>
[onPremisesSecurityIdentifier] =>
[onPremisesSyncEnabled] =>
[preferredDataLocation] =>
[proxyAddresses] => Array
(
[0] => SPO:SPO_ABCDE123456
[1] => SMTP:test@example.com
[2] => smtp:rest@example.onmicrosoft.com
)
[renewedDateTime] => 2019-04-18T15:09:57Z
[resourceBehaviorOptions] => Array
(
[0] => HideGroupInOutlook
[1] => WelcomeEmailDisabled
[2] => ConnectorsDisabled
[3] => SubscribeNewGroupMembers
)
[resourceProvisioningOptions] => Array
(
[0] => Team
)
[securityEnabled] =>
[visibility] => HiddenMembership
[extension_ABC123_Education_ObjectType] => Section
[onPremisesProvisioningErrors] => Array
(
)
)
)
因此,例如,当前没有获取 deletedDateTime
或 createdDateTime
的方法。我也想获得 extension_ABC123_Education_ObjectType
值。
是否有使用组模型执行此操作的简单方法?
谢谢
The issue is, some of these aren't accessible via getters
确实,在这种情况下,可以考虑使用以下方法通过 msgraph-sdk-php
.
假设扩展数据按组公开并命名为 contoso_grpstatus
:
GET https://graph.microsoft.com/v1.0/groups/{group-id}?$select=displayName,description,contoso_grpstatus
{
"displayName": "Group 123",
"description": "Group 123",
"contoso_grpstatus": {
"@odata.type": "#microsoft.graph.ComplexExtensionValue",
"Status": "Active"
}
}
其中 contoso_grpstatus
是 schema extension
{
"id": "contoso_grpstatus",
"description": "Contoso - Group status",
"targetTypes": [
"Group"
],
"status": "Available",
"owner": "d1433ee1-b39b-49b0-b022-b1072a0aee38",
"properties": [
{
"name": "Status",
"type": "String"
}
]
}
然后可以引入扩展 \Microsoft\Graph\Model\Group
的自定义组 class:
class GroupWithStatus extends \Microsoft\Graph\Model\Group{
public function getStatus()
{
if (array_key_exists("contoso_grpstatus", $this->_propDict)) {
return $this->_propDict["contoso_grpstatus"];
} else {
return null;
}
}
}
最后可以像这样检索组属性 (DisplayName
) 以及自定义数据 (contoso_grpstatus
):
$url = "/groups/$groupId?$select=displayName,contoso_grpstatus";
$group = $client->createRequest("GET", $url)
->setReturnType(GroupWithStatus::class)
->execute();
$displayName = $group->getDisplayName();
$status = $group->getStatus(); //custom data property