查找 Amazon Pinpoint 项目中的端点 - Amazon Pinpoint

终止支持通知: AWS 将于 2026 年 10 月 30 日终止对亚马逊 Pinpoint 的支持。2026 年 10 月 30 日之后,您将无法再访问亚马逊 Pinpoint 控制台或亚马逊 Pinpoint 资源(终端节点、区段、活动、旅程和分析)。有关更多信息,请参阅 Amazon Pinpoint 终止支持。注意: APIs 与短信相关、语音、移动推送、OTP 和电话号码验证不受此更改的影响,并受 AWS 最终用户消息的支持。

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

查找 Amazon Pinpoint 项目中的端点

您可以查找已添加到 Amazon Pinpoint 项目的任何单个端点的详细信息。这些详细信息可能包含消息的目标地址、消息收发渠道、有关用户设备的数据、有关用户位置的数据以及记录在端点中的任何自定义属性。

要查找端点,需要用到端点 ID。如果您不知道该 ID,则可以改为导出来获取端点数据。要导出端点,请参阅将端点从 Amazon Pinpoint 导出到 Amazon S3 存储桶

示例

以下示例演示如何通过指定 ID 来查找某个端点。

AWS CLI

可以通过在 AWS CLI中运行命令来使用 Amazon Pinpoint。

例 获取端点命令

要查找端点,请使用 get-endpoint 命令:

$ aws pinpoint get-endpoint \ > --application-id application-id \ > --endpoint-id endpoint-id

其中:

  • application-id 是包含该端点的 Amazon Pinpoint 项目的 ID。

  • endpoint-id 是要查找的端点的 ID。

对此命令的响应是端点的 JSON 定义,如以下示例所示:

{ "EndpointResponse": { "Address": "1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a8b9c0d1e2f", "ApplicationId": "application-id", "Attributes": { "Interests": [ "Technology", "Music", "Travel" ] }, "ChannelType": "APNS", "CohortId": "63", "CreationDate": "2018-05-01T17:31:01.046Z", "Demographic": { "AppVersion": "1.0", "Make": "apple", "Model": "iPhone", "ModelVersion": "8", "Platform": "ios", "PlatformVersion": "11.3.1", "Timezone": "America/Los_Angeles" }, "EffectiveDate": "2018-05-07T19:03:29.963Z", "EndpointStatus": "ACTIVE", "Id": "example_endpoint", "Location": { "City": "Seattle", "Country": "US", "Latitude": 47.6, "Longitude": -122.3, "PostalCode": "98121" }, "Metrics": { "music_interest_level": 6.0, "travel_interest_level": 4.0, "technology_interest_level": 9.0 }, "OptOut": "ALL", "RequestId": "7f546cac-6858-11e8-adcd-2b5a07aab338", "User": { "UserAttributes": { "Gender": "Female", "FirstName": "Wang", "LastName": "Xiulan", "Age": "39" }, "UserId": "example_user" } } }
适用于 Java 的 AWS SDK

您可以通过使用 适用于 Java 的 AWS SDK提供的客户端在您的 Java 应用程序中使用 Amazon Pinpoint API。

例 代码

要查找端点,请初始化 GetEndpointRequest 对象。然后,将此对象传递到 AmazonPinpoint 客户端的 getEndpoint 方法:

import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; import com.google.gson.GsonBuilder; 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.GetEndpointResponse; import software.amazon.awssdk.services.pinpoint.model.PinpointException; import software.amazon.awssdk.services.pinpoint.model.GetEndpointRequest;
import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; import com.google.gson.GsonBuilder; 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.GetEndpointResponse; import software.amazon.awssdk.services.pinpoint.model.PinpointException; import software.amazon.awssdk.services.pinpoint.model.GetEndpointRequest; /** * 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 LookUpEndpoint { public static void main(String[] args) { final String usage = """ Usage: <appId> <endpoint> Where: appId - The ID of the application to delete. endpoint - The ID of the endpoint.\s """; if (args.length != 2) { System.out.println(usage); System.exit(1); } String appId = args[0]; String endpoint = args[1]; System.out.println("Looking up an endpoint point with ID: " + endpoint); PinpointClient pinpoint = PinpointClient.builder() .region(Region.US_EAST_1) .build(); lookupPinpointEndpoint(pinpoint, appId, endpoint); pinpoint.close(); } public static void lookupPinpointEndpoint(PinpointClient pinpoint, String appId, String endpoint) { try { GetEndpointRequest appRequest = GetEndpointRequest.builder() .applicationId(appId) .endpointId(endpoint) .build(); GetEndpointResponse result = pinpoint.getEndpoint(appRequest); EndpointResponse endResponse = result.endpointResponse(); // Uses the Google Gson library to pretty print the endpoint JSON. Gson gson = new GsonBuilder() .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) .setPrettyPrinting() .create(); String endpointJson = gson.toJson(endResponse); System.out.println(endpointJson); } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } System.out.println("Done"); } }

为了以可读格式打印端点数据,本示例使用 Google GSON 库将 EndpointResponse 对象转换为 JSON 字符串。

HTTP

可以通过直接向 REST API 发出 HTTP 请求来使用 Amazon Pinpoint。

例 GET 端点请求

要查找端点,请向端点资源发出 GET 请求:

GET /v1/apps/application_id/endpoints/endpoint_id HTTP/1.1 Host: pinpoint.us-east-1.amazonaws.com Content-Type: application/json Accept: application/json Cache-Control: no-cache

其中:

  • application-id 是包含该端点的 Amazon Pinpoint 项目的 ID。

  • endpoint-id 是要查找的端点的 ID。

对此请求的响应是端点的 JSON 定义,如以下示例所示:

{ "ChannelType": "APNS", "Address": "1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a8b9c0d1e2f", "EndpointStatus": "ACTIVE", "OptOut": "NONE", "RequestId": "b720cfa8-6924-11e8-aeda-0b22e0b0fa59", "Location": { "Latitude": 47.6, "Longitude": -122.3, "PostalCode": "98121", "City": "Seattle", "Country": "US" }, "Demographic": { "Make": "apple", "Model": "iPhone", "ModelVersion": "8", "Timezone": "America/Los_Angeles", "AppVersion": "1.0", "Platform": "ios", "PlatformVersion": "11.3.1" }, "EffectiveDate": "2018-06-06T00:58:19.865Z", "Attributes": { "Interests": [ "Technology", "Music", "Travel" ] }, "Metrics": { "music_interest_level": 6, "travel_interest_level": 4, "technology_interest_level": 9 }, "User": {}, "ApplicationId": "application_id", "Id": "example_endpoint", "CohortId": "39", "CreationDate": "2018-06-06T00:58:19.865Z" }

有关 Amazon Pinpoint API 中端点资源的更多信息,请参阅《Amazon Pinpoint API 参考》中的端点