本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
要更新或删除端点,需要端点 ID。因此,如果要对一个 Amazon Pinpoint 项目中的所有端点执行这些操作,第一步就是列出属于该项目的所有端点 ID。然后,可以遍历这些 ID 以执行诸如全局添加属性或删除项目中的所有端点之类的操作。
以下示例使用 AWS SDK for Java 并执行以下操作:
-
调用从 Amazon Pinpoint 导出端点的示例代码中的示例
exportEndpointsToS3
方法。此方法从 Amazon Pinpoint 项目导出端点定义。端点定义作为 gzip 文件添加到 Amazon S3 存储桶。 -
下载导出的 gzip 文件。
-
读取 gzip 文件并从每个端点的 JSON 定义获取端点 ID。
-
将端点 ID 输出到控制台。
-
通过删除 Amazon Pinpoint 添加到 Amazon S3 的文件来清理。
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.pinpoint.PinpointClient;
import software.amazon.awssdk.services.pinpoint.model.EndpointResponse;
import software.amazon.awssdk.services.pinpoint.model.GetUserEndpointsRequest;
import software.amazon.awssdk.services.pinpoint.model.GetUserEndpointsResponse;
import software.amazon.awssdk.services.pinpoint.model.PinpointException;
import java.util.List;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.pinpoint.PinpointClient;
import software.amazon.awssdk.services.pinpoint.model.EndpointResponse;
import software.amazon.awssdk.services.pinpoint.model.GetUserEndpointsRequest;
import software.amazon.awssdk.services.pinpoint.model.GetUserEndpointsResponse;
import software.amazon.awssdk.services.pinpoint.model.PinpointException;
import java.util.List;
/**
* Before running this Java V2 code example, set up your development
* environment, including your credentials.
*
* For more information, see the following documentation topic:
*
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
*/
public class ListEndpointIds {
public static void main(String[] args) {
final String usage = """
Usage: <applicationId> <userId>
Where:
applicationId - The ID of the Amazon Pinpoint application that has the endpoint.
userId - The user id applicable to the endpoints""";
if (args.length != 2) {
System.out.println(usage);
System.exit(1);
}
String applicationId = args[0];
String userId = args[1];
PinpointClient pinpoint = PinpointClient.builder()
.region(Region.US_EAST_1)
.build();
listAllEndpoints(pinpoint, applicationId, userId);
pinpoint.close();
}
public static void listAllEndpoints(PinpointClient pinpoint,
String applicationId,
String userId) {
try {
GetUserEndpointsRequest endpointsRequest = GetUserEndpointsRequest.builder()
.userId(userId)
.applicationId(applicationId)
.build();
GetUserEndpointsResponse response = pinpoint.getUserEndpoints(endpointsRequest);
List<EndpointResponse> endpoints = response.endpointsResponse().item();
// Display the results.
for (EndpointResponse endpoint : endpoints) {
System.out.println("The channel type is: " + endpoint.channelType());
System.out.println("The address is " + endpoint.address());
}
} catch (PinpointException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
}
有关完整的 SDK 示例,请参阅 GitHub