chatgpt扩展程序添加了不能用 使用扩展向资源添加自定义数据

AI资讯1年前 (2023)发布 fengdao
28 0

本文内容

Graph 提供单个 API 终结点,以通过 用户 和 消息 等资源访问以人为本的丰富数据和见解。 还可以通过将自定义属性添加到资源实例扩展 Graph,而无需使用外部数据存储。

在本文中,我们将讨论 Graph 如何支持扩展其资源、添加自定义属性的可用选项,以及何时使用它们。

重要

请勿使用扩展存储敏感的个人身份信息,例如帐户凭据、政府标识号、持卡人数据、财务帐户数据、医疗保健信息或敏感的背景信息。

本文中提到的扩展与 自定义安全属性不相似。 若要了解它们的差异,请参阅

为什么要向 Graph 添加自定义数据? Graph 中的自定义数据选项

Graph 提供了四种类型的扩展来添加自定义数据。

扩展属性

Azure AD 提供一组 15 个扩展属性,其中包含用户和设备资源上的预定义名称。 这些属性最初是在本地 (AD) 和 中提供的自定义属性。 但现在其用途已不仅限于通过 Graph 将本地 AD 和 数据同步到 Azure AD。

开发者体验

可以使用这 15 个属性分别通过 和 属性在 用户 或 设备 资源实例上存储字符串值。 在创建新资源实例或更新现有资源实例时,可以分配这些值。 还可以按值进行筛选。

在扩展属性中添加或更新数据

以下示例演示如何使用 PATCH 方法通过更新操作将数据存储在 中,并从 中删除现有数据。

PATCH https://graph.microsoft.com/v1.0/users/071cc716-8147-4397-a5ba-b2105951cc0b
{
    "onPremisesExtensionAttributes": {
        "extensionAttribute1": "skypeId.adeleVance",
        "extensionAttribute13": null
    }
}


// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new User
{
	OnPremisesExtensionAttributes = new OnPremisesExtensionAttributes
	{
		ExtensionAttribute1 = "skypeId.adeleVance",
		ExtensionAttribute13 = null,
	},
};
var result = await graphClient.Users["{user-id}"].PatchAsync(requestBody);

阅读 SDK 文档详细了解如何将 SDK 添加到 项目并 创建 实例。


// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc users patch --user-id {user-id}

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


import (
	  "context"
	  msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
	  graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
	  //other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewUser()
onPremisesExtensionAttributes := graphmodels.NewOnPremisesExtensionAttributes()
extensionAttribute1 := "skypeId.adeleVance"
onPremisesExtensionAttributes.SetExtensionAttribute1(&extensionAttribute1) 
extensionAttribute13 := null
onPremisesExtensionAttributes.SetExtensionAttribute13(&extensionAttribute13) 
requestBody.SetOnPremisesExtensionAttributes(onPremisesExtensionAttributes)
users, err := graphClient.Users().ByUserId("user-id").Patch(context.Background(), requestBody, nil)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
User user = new User();
OnPremisesExtensionAttributes onPremisesExtensionAttributes = new OnPremisesExtensionAttributes();
onPremisesExtensionAttributes.extensionAttribute1 = "skypeId.adeleVance";
onPremisesExtensionAttributes.extensionAttribute13 = null;
user.onPremisesExtensionAttributes = onPremisesExtensionAttributes;
graphClient.users("071cc716-8147-4397-a5ba-b2105951cc0b")
	.buildRequest()
	.patch(user);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


const options = {
	authProvider,
};
const client = Client.init(options);
const user = {
    onPremisesExtensionAttributes: {
        extensionAttribute1: 'skypeId.adeleVance',
        extensionAttribute13: null
    }
};
await client.api('/users/071cc716-8147-4397-a5ba-b2105951cc0b')
	.update(user);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


setExtensionAttribute1('skypeId.adeleVance');
$onPremisesExtensionAttributes->setExtensionAttribute13(null);
$requestBody->setOnPremisesExtensionAttributes($onPremisesExtensionAttributes);
$result = $graphServiceClient->users()->byUserId('user-id')->patch($requestBody)->wait();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = User(
	on_premises_extension_attributes = OnPremisesExtensionAttributes(
		extension_attribute1 = "skypeId.adeleVance",
		extension_attribute13 = None,
	),
)
result = await graph_client.users.by_user_id('user-id').patch(body = request_body)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

请求会返回 204 No 响应对象。

读取扩展属性请求

GET https://graph.microsoft.com/v1.0/users?$select=id,displayName,onPremisesExtensionAttributes


// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var result = await graphClient.Users.GetAsync((requestConfiguration) =>
{
	requestConfiguration.QueryParameters.Select = new string []{ "id","displayName","onPremisesExtensionAttributes" };
});

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc users list --select "id,displayName,onPremisesExtensionAttributes"

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


import (
	  "context"
	  msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
	  graphusers "github.com/microsoftgraph/msgraph-sdk-go/users"
	  //other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestParameters := &graphusers.UsersRequestBuilderGetQueryParameters{
	Select: [] string {"id","displayName","onPremisesExtensionAttributes"},
}
configuration := &graphusers.UsersRequestBuilderGetRequestConfiguration{
	QueryParameters: requestParameters,
}
users, err := graphClient.Users().Get(context.Background(), configuration)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
UserCollectionPage users = graphClient.users()
	.buildRequest()
	.select("id,displayName,onPremisesExtensionAttributes")
	.get();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


const options = {
	authProvider,
};
const client = Client.init(options);
let users = await client.api('/users')
	.select('id,displayName,onPremisesExtensionAttributes')
	.get();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


select = ["id","displayName","onPremisesExtensionAttributes"];
$requestConfiguration->queryParameters = $queryParameters;
$result = $graphServiceClient->users()->get($requestConfiguration)->wait();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


Import-Module Microsoft.Graph.Users
Get-MgUser -Property "id,displayName,onPremisesExtensionAttributes" 

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
query_params = UsersRequestBuilder.UsersRequestBuilderGetQueryParameters(
		select = ["id","displayName","onPremisesExtensionAttributes"],
)
request_configuration = UsersRequestBuilder.UsersRequestBuilderGetRequestConfiguration(
query_parameters = query_params,
)
result = await graph_client.users.get(request_configuration = request_configuration)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

响应

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(id,displayName,onPremisesExtensionAttributes)",
    "value": [
        {
            "id": "071cc716-8147-4397-a5ba-b2105951cc0b",
            "displayName": "Adele Vance",
            "onPremisesExtensionAttributes": {
                "extensionAttribute1": "Contractor",
                "extensionAttribute2": "50",
                "extensionAttribute3": null,
                "extensionAttribute4": "1478354",
                "extensionAttribute5": "10239390",
                "extensionAttribute6": null,
                "extensionAttribute7": null,
                "extensionAttribute8": null,
                "extensionAttribute9": null,
                "extensionAttribute10": "11",
                "extensionAttribute11": null,
                "extensionAttribute12": "/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF47SPDLT)/cn=Recipients/cn=5ee781fc7egc7aa0b9394bddb44e7f04-Adele Vance",
                "extensionAttribute13": null,
                "extensionAttribute14": null,
                "extensionAttribute15": null
            }
        }
    ]
}

使用扩展属性属性的注意事项

对象只能更新未从本地 AD 同步的对象。

15 个扩展属性已在 Graph 中预定义,无法更改其属性名称。 因此,不能将自定义名称(如 )用于扩展属性。 这要求你和组织知道正在使用的扩展属性属性,以便其他应用不会无意中覆盖这些值。

目录 (Azure AD) 扩展

目录扩展 为开发人员提供了目录对象的强类型化、可发现和可筛选的扩展体验。

目录扩展首先通过 创建 操作在应用程序上注册,并且必须显式面向特定的和受支持的目录对象。 在应用程序获得用户或管理员同意后,扩展属性将立即在租户中可以访问。 租户中的所有授权应用程序都可以读取和写入目标目录对象实例上定义的任何扩展属性上的数据。

有关可指定为目录扩展的目标对象的资源类型的列表,请参阅 。

开发者体验

目录扩展定义通过 资源及其关联的方法进行管理。 数据通过用于管理资源实例的 REST API 请求进行管理。

定义目录扩展

必须先定义目录扩展,然后才能将目录扩展添加到资源实例。

请求

在以下请求中, -1871-485c-8c7b- 是拥有目录扩展的应用程序的对象 ID。 可以创建存储值集合的目录扩展。

POST https://graph.microsoft.com/v1.0/applications/30a5435a-1871-485c-8c7b-65f69e287e7b/extensionProperties
{
    "name": "jobGroupTracker",
    "dataType": "String",
    "targetObjects": [
        "User"
    ]
}


// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new ExtensionProperty
{
	Name = "jobGroupTracker",
	DataType = "String",
	TargetObjects = new List
	{
		"User",
	},
};
var result = await graphClient.Applications["{application-id}"].ExtensionProperties.PostAsync(requestBody);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc applications extension-properties create --application-id {application-id}

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


import (
	  "context"
	  msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
	  graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
	  //other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewExtensionProperty()
name := "jobGroupTracker"
requestBody.SetName(&name) 
dataType := "String"
requestBody.SetDataType(&dataType) 
targetObjects := []string {
	"User",
}
requestBody.SetTargetObjects(targetObjects)
extensionProperties, err := graphClient.Applications().ByApplicationId("application-id").ExtensionProperties().Post(context.Background(), requestBody, nil)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
ExtensionProperty extensionProperty = new ExtensionProperty();
extensionProperty.name = "jobGroupTracker";
extensionProperty.dataType = "String";
LinkedList targetObjectsList = new LinkedList();
targetObjectsList.add("User");
extensionProperty.targetObjects = targetObjectsList;
graphClient.applications("30a5435a-1871-485c-8c7b-65f69e287e7b").extensionProperties()
	.buildRequest()
	.post(extensionProperty);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


const options = {
	authProvider,
};
const client = Client.init(options);
const extensionProperty = {
    name: 'jobGroupTracker',
    dataType: 'String',
    targetObjects: [
        'User'
    ]
};
await client.api('/applications/30a5435a-1871-485c-8c7b-65f69e287e7b/extensionProperties')
	.post(extensionProperty);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


setName('jobGroupTracker');
$requestBody->setDataType('String');
$requestBody->setTargetObjects(['User', 	]);
$result = $graphServiceClient->applications()->byApplicationId('application-id')->extensionProperties()->post($requestBody)->wait();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = ExtensionProperty(
	name = "jobGroupTracker",
	data_type = "String",
	target_objects = [
		"User",
	]
)
result = await graph_client.applications.by_application_id('application-id').extension_properties.post(body = request_body)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

响应

使用遵循以下命名约定的扩展名创建名为 的目录扩展属性:{appId–}_{-name}。

HTTP/1.1 201 Created
Content-type: application/json
{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#applications('30a5435a-1871-485c-8c7b-65f69e287e7b')/extensionProperties/$entity",
    "id": "4e3dbc8f-ca32-41b4-825a-346215d7d20f",
    "deletedDateTime": null,
    "appDisplayName": "HR-sync-app",
    "dataType": "String",
    "isSyncedFromOnPremises": false,
    "name": "extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker",
    "targetObjects": [
        "User"
    ]
}

将目录扩展属性添加到目标对象

定义目录扩展后,现在可以将其添加到目标对象类型的实例。 在创建目标对象的新实例或更新现有对象时,可以将数据存储在目录扩展中。 以下示例演示如何在创建新 用户 对象时将数据存储在目录扩展中。

POST https://graph.microsoft.com/v1.0/users
{
    "accountEnabled": true,
    "displayName": "Adele Vance",
    "mailNickname": "AdeleV",
    "userPrincipalName": "AdeleV@contoso.com",
    "passwordProfile": {
        "forceChangePasswordNextSignIn": false,
        "password": "xWwvJ]6NMw+bWH-d"
    },
    "extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker": "JobGroupN"
}


// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new User
{
	AccountEnabled = true,
	DisplayName = "Adele Vance",
	MailNickname = "AdeleV",
	UserPrincipalName = "AdeleV@contoso.com",
	PasswordProfile = new PasswordProfile
	{
		ForceChangePasswordNextSignIn = false,
		Password = "xWwvJ]6NMw+bWH-d",
	},
	AdditionalData = new Dictionary
	{
		{
			"extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker" , "JobGroupN"
		},
	},
};
var result = await graphClient.Users.PostAsync(requestBody);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc users create

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


import (
	  "context"
	  msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
	  graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
	  //other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewUser()
accountEnabled := true
requestBody.SetAccountEnabled(&accountEnabled) 
displayName := "Adele Vance"
requestBody.SetDisplayName(&displayName) 
mailNickname := "AdeleV"
requestBody.SetMailNickname(&mailNickname) 
userPrincipalName := "AdeleV@contoso.com"
requestBody.SetUserPrincipalName(&userPrincipalName) 
passwordProfile := graphmodels.NewPasswordProfile()
forceChangePasswordNextSignIn := false
passwordProfile.SetForceChangePasswordNextSignIn(&forceChangePasswordNextSignIn) 
password := "xWwvJ]6NMw+bWH-d"
passwordProfile.SetPassword(&password) 
requestBody.SetPasswordProfile(passwordProfile)
additionalData := map[string]interface{}{
	"extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker" : "JobGroupN", 
}
requestBody.SetAdditionalData(additionalData)
users, err := graphClient.Users().Post(context.Background(), requestBody, nil)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


const options = {
	authProvider,
};
const client = Client.init(options);
const user = {
    accountEnabled: true,
    displayName: 'Adele Vance',
    mailNickname: 'AdeleV',
    userPrincipalName: 'AdeleV@contoso.com',
    passwordProfile: {
        forceChangePasswordNextSignIn: false,
        password: 'xWwvJ]6NMw+bWH-d'
    },
    extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker: 'JobGroupN'
};
await client.api('/users')
	.post(user);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


setAccountEnabled(true);
$requestBody->setDisplayName('Adele Vance');
$requestBody->setMailNickname('AdeleV');
$requestBody->setUserPrincipalName('AdeleV@contoso.com');
$passwordProfile = new PasswordProfile();
$passwordProfile->setForceChangePasswordNextSignIn(false);
$passwordProfile->setPassword('xWwvJ]6NMw+bWH-d');
$requestBody->setPasswordProfile($passwordProfile);
$additionalData = [
	'extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker' => 'JobGroupN',
];
$requestBody->setAdditionalData($additionalData);
$result = $graphServiceClient->users()->post($requestBody)->wait();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = User(
	account_enabled = True,
	display_name = "Adele Vance",
	mail_nickname = "AdeleV",
	user_principal_name = "AdeleV@contoso.com",
	password_profile = PasswordProfile(
		force_change_password_next_sign_in = False,
		password = "xWwvJ]6NMw+bWH-d",
	),
	additional_data = {
			"extension_b7d8e648520f41d3b9c0fdeb91768a0a_job_group_tracker" : "JobGroupN",
	}
)
result = await graph_client.users.post(body = request_body)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

请求会在响应正文中返回 201 响应代码和 用户对象。

检索目录扩展

以下示例演示如何在资源实例上显示目录扩展和关联数据。 默认情况下,将通过 beta 终结点返回扩展属性,但仅在 $ 时通过 v1.0 终结点返回。

请求

GET https://graph.microsoft.com/beta/users?$select=id,displayName,extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker,extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable


// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var result = await graphClient.Users.GetAsync((requestConfiguration) =>
{
	requestConfiguration.QueryParameters.Select = new string []{ "id","displayName","extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker","extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable" };
});

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc-beta users list --select "id,displayName,extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker,extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable"

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


import (
	  "context"
	  msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
	  graphusers "github.com/microsoftgraph/msgraph-beta-sdk-go/users"
	  //other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestParameters := &graphusers.UsersRequestBuilderGetQueryParameters{
	Select: [] string {"id","displayName","extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker","extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable"},
}
configuration := &graphusers.UsersRequestBuilderGetRequestConfiguration{
	QueryParameters: requestParameters,
}
users, err := graphClient.Users().Get(context.Background(), configuration)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
UserCollectionPage users = graphClient.users()
	.buildRequest()
	.select("id,displayName,extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker,extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable")
	.get();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


const options = {
	authProvider,
};
const client = Client.init(options);
let users = await client.api('/users')
	.version('beta')
	.select('id,displayName,extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker,extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable')
	.get();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


select = ["id","displayName","extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker","extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable"];
$requestConfiguration->queryParameters = $queryParameters;
$result = $graphServiceClient->users()->get($requestConfiguration)->wait();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


Import-Module Microsoft.Graph.Beta.Users
Get-MgBetaUser -Property "id,displayName,extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker,extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable" 

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
query_params = UsersRequestBuilder.UsersRequestBuilderGetQueryParameters(
		select = ["id","displayName","extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker","extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable"],
)
request_configuration = UsersRequestBuilder.UsersRequestBuilderGetRequestConfiguration(
query_parameters = query_params,
)
result = await graph_client.users.get(request_configuration = request_configuration)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

响应

HTTP/1.1 200 OK
Content-type: application/json
{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(id,displayName,extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker,extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable)",
    "value": [
        {
            "id": "63384f56-42d2-4aa7-b1d6-b10c78f143a2",
            "displayName": "Adele Vance",
            "extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker": "E4",
            "extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable": true
        }
    ]
}

扩展程序怎么添加_扩展程序有什么用_chatgpt扩展程序添加了不能用

更新或删除目录扩展

若要更新或删除资源实例的目录扩展的值,请使用 PATCH 方法。 若要删除扩展属性及其关联的值,请将其值设置为 null。

以下请求更新一个目录扩展的值,并删除另一个扩展属性。

PATCH https://graph.microsoft.com/v1.0/users/63384f56-42d2-4aa7-b1d6-b10c78f143a2
{
    "extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable": null,
    "extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker": "E4"
}


// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new User
{
	AdditionalData = new Dictionary
	{
		{
			"extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable" , null
		},
		{
			"extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker" , "E4"
		},
	},
};
var result = await graphClient.Users["{user-id}"].PatchAsync(requestBody);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc users patch --user-id {user-id}

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


import (
	  "context"
	  msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
	  graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
	  //other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewUser()
additionalData := map[string]interface{}{
	extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable := null
requestBody.SetExtension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable(&extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable) 
	"extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker" : "E4", 
}
requestBody.SetAdditionalData(additionalData)
users, err := graphClient.Users().ByUserId("user-id").Patch(context.Background(), requestBody, nil)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


const options = {
	authProvider,
};
const client = Client.init(options);
const user = {
    extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable: null,
    extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker: 'E4'
};
await client.api('/users/63384f56-42d2-4aa7-b1d6-b10c78f143a2')
	.update(user);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


 null,
	'extension_b7d8e648520f41d3b9c0fdeb91768a0a_jobGroupTracker' => 'E4',
];
$requestBody->setAdditionalData($additionalData);
$result = $graphServiceClient->users()->byUserId('user-id')->patch($requestBody)->wait();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = User(
	additional_data = {
			"extension_b7d8e648520f41d3b9c0fdeb91768a0a_permanent_pensionable" : None,
			"extension_b7d8e648520f41d3b9c0fdeb91768a0a_job_group_tracker" : "E4",
	}
)
result = await graph_client.users.by_user_id('user-id').patch(body = request_body)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

请求会返回 204 No 响应代码。

使用目录扩展的注意事项

如果意外删除了目录扩展定义,则存储在关联属性中的任何数据都将无法发现。 若要解决此问题,请在同一所有者应用上创建新的目录扩展定义,其名称与已删除的定义完全相同。

在相应的扩展属性更新为 null之前删除定义对象时,该属性仍将计入对象的 100 限制。

在删除关联的扩展属性中的数据之前删除定义时,无法通过 Graph 知道扩展属性是否存在,即使不可发现属性计数超过 100 限制也是如此。

删除主租户中的所有者应用会使关联的目录扩展及其数据无法被发现。 还原所有者应用会还原目录扩展定义, 但不会 立即发现目录扩展属性或其数据。 这是因为还原应用不会自动还原租户中的关联服务主体。 若要使目录扩展属性及其数据可被发现,请创建新的服务主体或还原已删除的服务主体。 不会对已同意应用的其他租户进行更改。

架构扩展

Graph 架构扩展 在概念上类似于目录扩展。 首先,定义架构扩展。 然后,使用它扩展具有强类型自定义属性的支持资源实例。 此外,还可以控制架构扩展的,让它可被其他应用发现。

有关支持架构扩展的资源类型列表,请参阅 。

开发者体验

在创建架构扩展定义时,你必须提供其 id 的唯一名称。提供两个命名选项:

ID 将是将数据存储在扩展资源实例上的复杂类型的名称。

注册架构扩展后,当处于) 状态时 ,与关联的所有者应用程序 (同一租户中的所有应用程序都可以使用该扩展,或者当处于) 状态时 ,任何租户 (中的所有应用程序都可以使用该扩展。 与目录扩展一样,授权应用可以读取和写入目标对象上定义的任何扩展上的数据。

使用单独的 API 操作集管理相应架构扩展属性中的架构扩展 定义 和数据。 要管理扩展资源实例上的架构扩展数据,请使用你用于管理资源实例的同一 REST 请求。

使用 GET 读取租户中所有用户或单个用户的架构扩展属性。定义架构扩展请求

POST https://graph.microsoft.com/v1.0/schemaExtensions
{
    "id": "graphLearnCourses",
    "description": "Graph Learn training courses extensions",
    "targetTypes": [
        "user"
    ],
    "properties": [
        {
            "name": "courseId",
            "type": "Integer"
        },
        {
            "name": "courseName",
            "type": "String"
        },
        {
            "name": "courseType",
            "type": "String"
        }
    ]
}


// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new SchemaExtension
{
	Id = "graphLearnCourses",
	Description = "Graph Learn training courses extensions",
	TargetTypes = new List
	{
		"user",
	},
	Properties = new List
	{
		new ExtensionSchemaProperty
		{
			Name = "courseId",
			Type = "Integer",
		},
		new ExtensionSchemaProperty
		{
			Name = "courseName",
			Type = "String",
		},
		new ExtensionSchemaProperty
		{
			Name = "courseType",
			Type = "String",
		},
	},
};
var result = await graphClient.SchemaExtensions.PostAsync(requestBody);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc schema-extensions create

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


import (
	  "context"
	  msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
	  graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
	  //other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewSchemaExtension()
id := "graphLearnCourses"
requestBody.SetId(&id) 
description := "Graph Learn training courses extensions"
requestBody.SetDescription(&description) 
targetTypes := []string {
	"user",
}
requestBody.SetTargetTypes(targetTypes)
extensionSchemaProperty := graphmodels.NewExtensionSchemaProperty()
name := "courseId"
extensionSchemaProperty.SetName(&name) 
type := "Integer"
extensionSchemaProperty.SetType(&type) 
extensionSchemaProperty1 := graphmodels.NewExtensionSchemaProperty()
name := "courseName"
extensionSchemaProperty1.SetName(&name) 
type := "String"
extensionSchemaProperty1.SetType(&type) 
extensionSchemaProperty2 := graphmodels.NewExtensionSchemaProperty()
name := "courseType"
extensionSchemaProperty2.SetName(&name) 
type := "String"
extensionSchemaProperty2.SetType(&type) 
properties := []graphmodels.ExtensionSchemaPropertyable {
	extensionSchemaProperty,
	extensionSchemaProperty1,
	extensionSchemaProperty2,
}
requestBody.SetProperties(properties)
schemaExtensions, err := graphClient.SchemaExtensions().Post(context.Background(), requestBody, nil)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
SchemaExtension schemaExtension = new SchemaExtension();
schemaExtension.id = "graphLearnCourses";
schemaExtension.description = "Graph Learn training courses extensions";
LinkedList targetTypesList = new LinkedList();
targetTypesList.add("user");
schemaExtension.targetTypes = targetTypesList;
LinkedList propertiesList = new LinkedList();
ExtensionSchemaProperty properties = new ExtensionSchemaProperty();
properties.name = "courseId";
properties.type = "Integer";
propertiesList.add(properties);
ExtensionSchemaProperty properties1 = new ExtensionSchemaProperty();
properties1.name = "courseName";
properties1.type = "String";
propertiesList.add(properties1);
ExtensionSchemaProperty properties2 = new ExtensionSchemaProperty();
properties2.name = "courseType";
properties2.type = "String";
propertiesList.add(properties2);
schemaExtension.properties = propertiesList;
graphClient.schemaExtensions()
	.buildRequest()
	.post(schemaExtension);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


const options = {
	authProvider,
};
const client = Client.init(options);
const schemaExtension = {
    id: 'graphLearnCourses',
    description: 'Graph Learn training courses extensions',
    targetTypes: [
        'user'
    ],
    properties: [
        {
            name: 'courseId',
            type: 'Integer'
        },
        {
            name: 'courseName',
            type: 'String'
        },
        {
            name: 'courseType',
            type: 'String'
        }
    ]
};
await client.api('/schemaExtensions')
	.post(schemaExtension);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


setId('graphLearnCourses');
$requestBody->setDescription('Graph Learn training courses extensions');
$requestBody->setTargetTypes(['user', 	]);
$propertiesExtensionSchemaProperty1 = new ExtensionSchemaProperty();
$propertiesExtensionSchemaProperty1->setName('courseId');
$propertiesExtensionSchemaProperty1->setType('Integer');
$propertiesArray []= $propertiesExtensionSchemaProperty1;
$propertiesExtensionSchemaProperty2 = new ExtensionSchemaProperty();
$propertiesExtensionSchemaProperty2->setName('courseName');
$propertiesExtensionSchemaProperty2->setType('String');
$propertiesArray []= $propertiesExtensionSchemaProperty2;
$propertiesExtensionSchemaProperty3 = new ExtensionSchemaProperty();
$propertiesExtensionSchemaProperty3->setName('courseType');
$propertiesExtensionSchemaProperty3->setType('String');
$propertiesArray []= $propertiesExtensionSchemaProperty3;
$requestBody->setProperties($propertiesArray);
$result = $graphServiceClient->schemaExtensions()->post($requestBody)->wait();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = SchemaExtension(
	id = "graphLearnCourses",
	description = "Graph Learn training courses extensions",
	target_types = [
		"user",
	]
	properties = [
		ExtensionSchemaProperty(
			name = "courseId",
			type = "Integer",
		),
		ExtensionSchemaProperty(
			name = "courseName",
			type = "String",
		),
		ExtensionSchemaProperty(
			name = "courseType",
			type = "String",
		),
	]
)
result = await graph_client.schema_extensions.post(body = request_body)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

响应

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#schemaExtensions/$entity",
    "id": "extkmpdyld2_graphLearnCourses",
    "description": "Graph Learn training courses extensions",
    "targetTypes": [
        "user"
    ],
    "status": "InDevelopment",
    "properties": [
        {
            "name": "courseId",
            "type": "Integer"
        },
        {
            "name": "courseName",
            "type": "String"
        },
        {
            "name": "courseType",
            "type": "String"
        }
    ]
}

将架构扩展添加到资源实例

定义架构扩展后,现在可以将扩展属性添加到目标对象类型的实例。 在创建目标对象的新实例或更新现有对象时,可以将数据存储在架构扩展中。 下面的示例演示如何在创建新的用户对象时将数据存储在架构扩展属性中。

POST https://graph.microsoft.com/beta/users
{
    "accountEnabled": true,
    "displayName": "Adele Vance",
    "mailNickname": "AdeleV",
    "userPrincipalName": "AdeleV@contoso.com",
    "passwordProfile": {
        "forceChangePasswordNextSignIn": false,
        "password": "xWwvJ]6NMw+bWH-d"
    },
    "extkmpdyld2_graphLearnCourses": {
        "courseId": 100,
        "courseName": "Explore Microsoft Graph",
        "courseType": "Online"
    }
}


// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new User
{
	AccountEnabled = true,
	DisplayName = "Adele Vance",
	MailNickname = "AdeleV",
	UserPrincipalName = "AdeleV@contoso.com",
	PasswordProfile = new PasswordProfile
	{
		ForceChangePasswordNextSignIn = false,
		Password = "xWwvJ]6NMw+bWH-d",
	},
	AdditionalData = new Dictionary
	{
		{
			"extkmpdyld2_graphLearnCourses" , new 
			{
				CourseId = 100,
				CourseName = "Explore Microsoft Graph",
				CourseType = "Online",
			}
		},
	},
};
var result = await graphClient.Users.PostAsync(requestBody);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc-beta users create

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


import (
	  "context"
	  msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
	  graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
	  //other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewUser()
accountEnabled := true
requestBody.SetAccountEnabled(&accountEnabled) 
displayName := "Adele Vance"
requestBody.SetDisplayName(&displayName) 
mailNickname := "AdeleV"
requestBody.SetMailNickname(&mailNickname) 
userPrincipalName := "AdeleV@contoso.com"
requestBody.SetUserPrincipalName(&userPrincipalName) 
passwordProfile := graphmodels.NewPasswordProfile()
forceChangePasswordNextSignIn := false
passwordProfile.SetForceChangePasswordNextSignIn(&forceChangePasswordNextSignIn) 
password := "xWwvJ]6NMw+bWH-d"
passwordProfile.SetPassword(&password) 
requestBody.SetPasswordProfile(passwordProfile)
additionalData := map[string]interface{}{
extkmpdyld2_graphLearnCourses := graphmodels.New()
courseId := int32(100)
extkmpdyld2_graphLearnCourses.SetCourseId(&courseId) 
courseName := "Explore Microsoft Graph"
extkmpdyld2_graphLearnCourses.SetCourseName(&courseName) 
courseType := "Online"
extkmpdyld2_graphLearnCourses.SetCourseType(&courseType) 
	requestBody.SetExtkmpdyld2_graphLearnCourses(extkmpdyld2_graphLearnCourses)
}
requestBody.SetAdditionalData(additionalData)
users, err := graphClient.Users().Post(context.Background(), requestBody, nil)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


const options = {
	authProvider,
};
const client = Client.init(options);
const user = {
    accountEnabled: true,
    displayName: 'Adele Vance',
    mailNickname: 'AdeleV',
    userPrincipalName: 'AdeleV@contoso.com',
    passwordProfile: {
        forceChangePasswordNextSignIn: false,
        password: 'xWwvJ]6NMw+bWH-d'
    },
    extkmpdyld2_graphLearnCourses: {
        courseId: 100,
        courseName: 'Explore Microsoft Graph',
        courseType: 'Online'
    }
};
await client.api('/users')
	.version('beta')
	.post(user);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


setAccountEnabled(true);
$requestBody->setDisplayName('Adele Vance');
$requestBody->setMailNickname('AdeleV');
$requestBody->setUserPrincipalName('AdeleV@contoso.com');
$passwordProfile = new PasswordProfile();
$passwordProfile->setForceChangePasswordNextSignIn(false);
$passwordProfile->setPassword('xWwvJ]6NMw+bWH-d');
$requestBody->setPasswordProfile($passwordProfile);
$additionalData = [
	'extkmpdyld2_graphLearnCourses' => [
		'courseId' => 100,
		'courseName' => 'Explore Microsoft Graph',
		'courseType' => 'Online',
	],
];
$requestBody->setAdditionalData($additionalData);
$result = $graphServiceClient->users()->post($requestBody)->wait();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = User(
	account_enabled = True,
	display_name = "Adele Vance",
	mail_nickname = "AdeleV",
	user_principal_name = "AdeleV@contoso.com",
	password_profile = PasswordProfile(
		force_change_password_next_sign_in = False,
		password = "xWwvJ]6NMw+bWH-d",
	),
	additional_data = {
			"extkmpdyld2_graph_learn_courses" : (
				course_id = 100,
				course_name = "Explore Microsoft Graph",
				course_type = "Online",
			),
	}
)
result = await graph_client.users.post(body = request_body)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

请求会在响应正文中返回 201 响应代码和 对象

更新或删除架构扩展属性

使用 PATCH 操作更新架构扩展或删除现有架构扩展。 要从资源实例中删除扩展属性及其关联值,请将其值设置为 null。

以下示例删除 属性的值并更新 属性。 要完整删除 扩展属性,请将其值设置为 null。

PATCH https://graph.microsoft.com/beta/users/0668e673-908b-44ea-861d-0661297e1a3e
{
    "extkmpdyld2_graphLearnCourses": {
        "courseType": "Instructor-led",
        "courseId": null
    }
}


// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new User
{
	AdditionalData = new Dictionary
	{
		{
			"extkmpdyld2_graphLearnCourses" , new 
			{
				CourseType = "Instructor-led",
				CourseId = null,
			}
		},
	},
};
var result = await graphClient.Users["{user-id}"].PatchAsync(requestBody);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc-beta users patch --user-id {user-id}

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


import (
	  "context"
	  msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
	  graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
	  //other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewUser()
additionalData := map[string]interface{}{
extkmpdyld2_graphLearnCourses := graphmodels.New()
courseType := "Instructor-led"
extkmpdyld2_graphLearnCourses.SetCourseType(&courseType) 
	courseId := null
extkmpdyld2_graphLearnCourses.SetCourseId(&courseId) 
	requestBody.SetExtkmpdyld2_graphLearnCourses(extkmpdyld2_graphLearnCourses)
}
requestBody.SetAdditionalData(additionalData)
users, err := graphClient.Users().ByUserId("user-id").Patch(context.Background(), requestBody, nil)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


const options = {
	authProvider,
};
const client = Client.init(options);
const user = {
    extkmpdyld2_graphLearnCourses: {
        courseType: 'Instructor-led',
        courseId: null
    }
};
await client.api('/users/0668e673-908b-44ea-861d-0661297e1a3e')
	.version('beta')
	.update(user);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


 [
		'courseType' => 'Instructor-led',
		'courseId' => null,
	],
];
$requestBody->setAdditionalData($additionalData);
$result = $graphServiceClient->users()->byUserId('user-id')->patch($requestBody)->wait();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = User(
	additional_data = {
			"extkmpdyld2_graph_learn_courses" : (
				course_type = "Instructor-led",
				course_id = None,
			),
	}
)
result = await graph_client.users.by_user_id('user-id').patch(body = request_body)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

请求会返回 204 No 响应对象。

检索架构扩展属性

要读取资源实例上的架构扩展属性,请在 $ 请求中指定扩展名。

请求

GET https://graph.microsoft.com/beta/users/0668e673-908b-44ea-861d-0661297e1a3e?$select=id,displayName,extkmpdyld2_graphLearnCourses


// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var result = await graphClient.Users["{user-id}"].GetAsync((requestConfiguration) =>
{
	requestConfiguration.QueryParameters.Select = new string []{ "id","displayName","extkmpdyld2_graphLearnCourses" };
});

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc-beta users get --user-id {user-id} --select "id,displayName,extkmpdyld2_graphLearnCourses"

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


import (
	  "context"
	  msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
	  graphusers "github.com/microsoftgraph/msgraph-beta-sdk-go/users"
	  //other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestParameters := &graphusers.UserItemRequestBuilderGetQueryParameters{
	Select: [] string {"id","displayName","extkmpdyld2_graphLearnCourses"},
}
configuration := &graphusers.UserItemRequestBuilderGetRequestConfiguration{
	QueryParameters: requestParameters,
}
users, err := graphClient.Users().ByUserId("user-id").Get(context.Background(), configuration)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
User user = graphClient.users("0668e673-908b-44ea-861d-0661297e1a3e")
	.buildRequest()
	.select("id,displayName,extkmpdyld2_graphLearnCourses")
	.get();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


const options = {
	authProvider,
};
const client = Client.init(options);
let user = await client.api('/users/0668e673-908b-44ea-861d-0661297e1a3e')
	.version('beta')
	.select('id,displayName,extkmpdyld2_graphLearnCourses')
	.get();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


select = ["id","displayName","extkmpdyld2_graphLearnCourses"];
$requestConfiguration->queryParameters = $queryParameters;
$result = $graphServiceClient->users()->byUserId('user-id')->get($requestConfiguration)->wait();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


Import-Module Microsoft.Graph.Beta.Users
Get-MgBetaUser -UserId $userId -Property "id,displayName,extkmpdyld2_graphLearnCourses" 

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
query_params = UserRequestBuilder.UserRequestBuilderGetQueryParameters(
		select = ["id","displayName","extkmpdyld2_graphLearnCourses"],
)
request_configuration = UserRequestBuilder.UserRequestBuilderGetRequestConfiguration(
query_parameters = query_params,
)
result = await graph_client.users.by_user_id('user-id').get(request_configuration = request_configuration)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

响应

HTTP/1.1 200 OK
Content-type: application/json
{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#users(id,displayName,extkmpdyld2_graphLearnCourses)/$entity",
    "id": "63384f56-42d2-4aa7-b1d6-b10c78f143a2",
    "displayName": "Adele Vance",
    "extkmpdyld2_graphLearnCourses": {
        "@odata.type": "#microsoft.graph.ComplexExtensionValue",
        "courseType": "Instructor-led",
        "courseName": "Explore Microsoft Graph",
        "courseId": null
    }
}

使用架构扩展的注意事项

架构扩展必须具有所有者应用。 无法将架构扩展的所有权重新分配给其他应用。

删除架构扩展定义而不设置架构扩展, null 使属性及其关联的用户数据不可发现。

删除主租户中的所有者应用不会删除关联的架构扩展定义或属性及其存储的数据。 仍可为用户读取、删除或更新架构扩展属性。 但是,无法更新架构扩展定义。

开放扩展

Graph 开放扩展 是 ,可提供一种简单灵活的方式将非类型化数据直接添加到资源实例。 这些扩展不是强类型化、可发现或可筛选的。

有关支持 Graph 开放扩展的资源类型列表,请参阅 。

开发者体验

可通过资源实例的 扩展 导航属性访问开放扩展及其数据。 使用这些属性,可以对相关属性进行分组,以实现更轻松的访问和管理。

扩展程序有什么用_扩展程序怎么添加_chatgpt扩展程序添加了不能用

可在资源实例上动态定义和管理开放扩展。 对于每个对象,它们被视为唯一的,并且不需要为所有对象应用通用一致的模式。 例如,在同一租户中:

创建开放扩展

以下示例演示具有三个属性的开放扩展定义,以及如何在资源实例上显示自定义属性和关联数据。

POST https://graph.microsoft.com/v1.0/users/3fbd929d-8c56-4462-851e-0eb9a7b3a2a5/extensions
{
    "@odata.type": "#microsoft.graph.openTypeExtension",
    "extensionName": "com.contoso.socialSettings",
    "skypeId": "skypeId.AdeleV",
    "linkedInProfile": "www.linkedin.com/in/testlinkedinprofile",
    "xboxGamerTag": "AwesomeAdele",
    "id": "com.contoso.socialSettings"
}


// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new OpenTypeExtension
{
	OdataType = "#microsoft.graph.openTypeExtension",
	ExtensionName = "com.contoso.socialSettings",
	Id = "com.contoso.socialSettings",
	AdditionalData = new Dictionary
	{
		{
			"skypeId" , "skypeId.AdeleV"
		},
		{
			"linkedInProfile" , "www.linkedin.com/in/testlinkedinprofile"
		},
		{
			"xboxGamerTag" , "AwesomeAdele"
		},
	},
};
var result = await graphClient.Users["{user-id}"].Extensions.PostAsync(requestBody);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc users extensions create --user-id {user-id}

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


import (
	  "context"
	  msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
	  graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
	  //other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewExtension()
extensionName := "com.contoso.socialSettings"
requestBody.SetExtensionName(&extensionName) 
id := "com.contoso.socialSettings"
requestBody.SetId(&id) 
additionalData := map[string]interface{}{
	"skypeId" : "skypeId.AdeleV", 
	"linkedInProfile" : "www.linkedin.com/in/testlinkedinprofile", 
	"xboxGamerTag" : "AwesomeAdele", 
}
requestBody.SetAdditionalData(additionalData)
extensions, err := graphClient.Users().ByUserId("user-id").Extensions().Post(context.Background(), requestBody, nil)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


const options = {
	authProvider,
};
const client = Client.init(options);
const extension = {
    '@odata.type': '#microsoft.graph.openTypeExtension',
    extensionName: 'com.contoso.socialSettings',
    skypeId: 'skypeId.AdeleV',
    linkedInProfile: 'www.linkedin.com/in/testlinkedinprofile',
    xboxGamerTag: 'AwesomeAdele',
    id: 'com.contoso.socialSettings'
};
await client.api('/users/3fbd929d-8c56-4462-851e-0eb9a7b3a2a5/extensions')
	.post(extension);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


setOdataType('#microsoft.graph.openTypeExtension');
$requestBody->setExtensionName('com.contoso.socialSettings');
$requestBody->setId('com.contoso.socialSettings');
$additionalData = [
	'skypeId' => 'skypeId.AdeleV',
	'linkedInProfile' => 'www.linkedin.com/in/testlinkedinprofile',
	'xboxGamerTag' => 'AwesomeAdele',
];
$requestBody->setAdditionalData($additionalData);
$result = $graphServiceClient->users()->byUserId('user-id')->extensions()->post($requestBody)->wait();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = OpenTypeExtension(
	odata_type = "#microsoft.graph.openTypeExtension",
	extension_name = "com.contoso.socialSettings",
	id = "com.contoso.socialSettings",
	additional_data = {
			"skype_id" : "skypeId.AdeleV",
			"linked_in_profile" : "www.linkedin.com/in/testlinkedinprofile",
			"xbox_gamer_tag" : "AwesomeAdele",
	}
)
result = await graph_client.users.by_user_id('user-id').extensions.post(body = request_body)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

请求会在响应正文中返回 201 响应代码和 对象。

更新现有开放扩展

要更新开放扩展,必须在请求正文中指定其所有属性。 否则,未指定的属性将更新为 null 并从开放扩展中删除。

以下请求仅指定 和 属性。 属性的值正在更新,而 属性将保持不变。 此请求还会删除未指定的 属性。

PATCH https://graph.microsoft.com/v1.0/users/3fbd929d-8c56-4462-851e-0eb9a7b3a2a5/extensions/com.contoso.socialSettings
{
    "xboxGamerTag": "FierceAdele",
    "linkedInProfile": "www.linkedin.com/in/testlinkedinprofile"
}


// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Extension
{
	AdditionalData = new Dictionary
	{
		{
			"xboxGamerTag" , "FierceAdele"
		},
		{
			"linkedInProfile" , "www.linkedin.com/in/testlinkedinprofile"
		},
	},
};
var result = await graphClient.Users["{user-id}"].Extensions["{extension-id}"].PatchAsync(requestBody);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc users extensions patch --user-id {user-id} --extension-id {extension-id}

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


import (
	  "context"
	  msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
	  graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
	  //other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewExtension()
additionalData := map[string]interface{}{
	"xboxGamerTag" : "FierceAdele", 
	"linkedInProfile" : "www.linkedin.com/in/testlinkedinprofile", 
}
requestBody.SetAdditionalData(additionalData)
extensions, err := graphClient.Users().ByUserId("user-id").Extensions().ByExtensionId("extension-id").Patch(context.Background(), requestBody, nil)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


const options = {
	authProvider,
};
const client = Client.init(options);
const extension = {
    xboxGamerTag: 'FierceAdele',
    linkedInProfile: 'www.linkedin.com/in/testlinkedinprofile'
};
await client.api('/users/3fbd929d-8c56-4462-851e-0eb9a7b3a2a5/extensions/com.contoso.socialSettings')
	.update(extension);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


 'FierceAdele',
	'linkedInProfile' => 'www.linkedin.com/in/testlinkedinprofile',
];
$requestBody->setAdditionalData($additionalData);
$result = $graphServiceClient->users()->byUserId('user-id')->extensions()->byExtensionId('extension-id')->patch($requestBody)->wait();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = Extension(
	additional_data = {
			"xbox_gamer_tag" : "FierceAdele",
			"linked_in_profile" : "www.linkedin.com/in/testlinkedinprofile",
	}
)
result = await graph_client.users.by_user_id('user-id').extensions.by_extension_id('extension-id').patch(body = request_body)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

此请求会返回 204 No 响应代码。

检索开放扩展

GET https://graph.microsoft.com/v1.0/users/3fbd929d-8c56-4462-851e-0eb9a7b3a2a5/extensions/com.contoso.socialSettings
{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#users('3fbd929d-8c56-4462-851e-0eb9a7b3a2a5')/extensions/$entity",
    "@odata.type": "#microsoft.graph.openTypeExtension",
    "xboxGamerTag": "FierceAdele",
    "linkedInProfile": "www.linkedin.com/in/testlinkedinprofile",
    "id": "com.contoso.socialSettings"
}


// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new OpenTypeExtension
{
	OdataType = "#microsoft.graph.openTypeExtension",
	Id = "com.contoso.socialSettings",
	AdditionalData = new Dictionary
	{
		{
			"@odata.context" , "https://graph.microsoft.com/beta/$metadata#users('3fbd929d-8c56-4462-851e-0eb9a7b3a2a5')/extensions/$entity"
		},
		{
			"xboxGamerTag" , "FierceAdele"
		},
		{
			"linkedInProfile" , "www.linkedin.com/in/testlinkedinprofile"
		},
	},
};
var result = await graphClient.Users["{user-id}"].Extensions["{extension-id}"].GetAsync(requestBody);

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc users extensions get --user-id {user-id} --extension-id {extension-id}

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


import (
	  "context"
	  msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
	  graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
	  //other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewExtension()
id := "com.contoso.socialSettings"
requestBody.SetId(&id) 
additionalData := map[string]interface{}{
	"odataContext" : "https://graph.microsoft.com/beta/$metadata#users('3fbd929d-8c56-4462-851e-0eb9a7b3a2a5')/extensions/$entity", 
	"xboxGamerTag" : "FierceAdele", 
	"linkedInProfile" : "www.linkedin.com/in/testlinkedinprofile", 
}
requestBody.SetAdditionalData(additionalData)
extensions, err := graphClient.Users().ByUserId("user-id").Extensions().ByExtensionId("extension-id").Get(context.Background(), requestBody, nil)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Extension extension = graphClient.users("3fbd929d-8c56-4462-851e-0eb9a7b3a2a5").extensions("com.contoso.socialSettings")
	.buildRequest()
	.get();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


const options = {
	authProvider,
};
const client = Client.init(options);
let extension = await client.api('/users/3fbd929d-8c56-4462-851e-0eb9a7b3a2a5/extensions/com.contoso.socialSettings')
	.get();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


setOdataType('#microsoft.graph.openTypeExtension');
$requestBody->setId('com.contoso.socialSettings');
$additionalData = [
	'@odata.context' => 'https://graph.microsoft.com/beta/$metadata#users('3fbd929d-8c56-4462-851e-0eb9a7b3a2a5')/extensions/$entity',
	'xboxGamerTag' => 'FierceAdele',
	'linkedInProfile' => 'www.linkedin.com/in/testlinkedinprofile',
];
$requestBody->setAdditionalData($additionalData);
$result = $graphServiceClient->users()->byUserId('user-id')->extensions()->byExtensionId('extension-id')->get($requestBody)->wait();

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

Snippet not available

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。


# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = OpenTypeExtension(
	odata_type = "#microsoft.graph.openTypeExtension",
	id = "com.contoso.socialSettings",
	additional_data = {
			"@odata_context" : "https://graph.microsoft.com/beta/$metadata#users('3fbd929d-8c56-4462-851e-0eb9a7b3a2a5')/extensions/$entity",
			"xbox_gamer_tag" : "FierceAdele",
			"linked_in_profile" : "www.linkedin.com/in/testlinkedinprofile",
	}
)
result = await graph_client.users.by_user_id('user-id').extensions.by_extension_id('extension-id').get(body = request_body)

阅读 SDK 文档 ,详细了解如何将 SDK 添加到 项目并 创建 实例。

使用开放扩展的注意事项

删除创建者应用不会影响打开的扩展及其存储的数据。

扩展类型的比较

下表对扩展类型进行了对比和比较,这应有助于确定最适合你的方案的选项。

功能扩展属性 1-15目录扩展架构扩展开放扩展

支持的资源类型

user

设备

user

group

设备

组织

用户

group

联系人

设备

事件(用户和组日历)

邮件

组织

帖子

user

联系人

设备

事件1(用户和组日历)

邮件

组织

帖子

强类型

可以存储集合2

绑定到“所有者”应用程序

管理方式

Graph

管理中心

Graph

Graph

Graph

使用 AD 将数据从本地同步到扩展

是,对于用户

使用自定义扩展属性和数据创建 动态成员资格规则

© 版权声明

相关文章

暂无评论

暂无评论...