共享群组
本节介绍与其他用户共享群组以及管理共享请求的操作,可通过 ESPRMUser 实例(用于用户级操作)或 ESPRMGroup 实例(用于群组级操作)执行。
说明
使用 ESPRMAuth.getLoggedInUser 方法获取用户实例:
try {
const authInstance = ESPRMBase.getAuthInstance();
const userInstance = await authInstance.getLoggedInUser();
if (userInstance) {
// 使用 userInstance 进行群组操作
} else {
console.log("No user is currently logged in");
}
} catch (error) {
console.error("Error getting logged in user:", error);
}
用户级操作
共享群组
使用 shareGroups 方法与其他用户共享一个或多个群组。
try {
const shareRequest = {
username: "target_username",
groupIds: ["group_id_1", "group_id_2"],
makePrimary: false,
metadata: {
description: "Shared for home automation access",
},
};
const requestId = await userInstance.shareGroups(shareRequest);
console.log("Group sharing request created:", requestId);
} catch (error) {
console.error("Error sharing groups:", error);
}
转移群组
使用 transferGroups 方法将一个或多个群组的所有权转移给其他用户。
try {
const transferRequest = {
toUserName: "new_owner@example.com",
groupIds: ["group_id_1", "group_id_2"],
selfToSecondary: false,
};
const requestId = await userInstance.transferGroups(transferRequest);
console.log("Group transfer request created:", requestId);
} catch (error) {
console.error("Error transferring groups:", error);
}
获取已发出的群组共享请求
使用 getIssuedGroupSharingRequests 方法检索已发出的群组共享请求。
try {
const response = await userInstance.getIssuedGroupSharingRequests(10);
console.log("Issued sharing requests:", response.sharedRequests);
console.log("Has more requests:", response.hasNext);
} catch (error) {
console.error("Error getting issued sharing requests:", error);
}