本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
UpdateEndpoint
搭配 使用 AWS SDK
下列程式碼範例示範如何使用 UpdateEndpoint
。
- Java
-
- SDK 適用於 Java 2.x
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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.EndpointRequest; import software.amazon.awssdk.services.pinpoint.model.UpdateEndpointRequest; import software.amazon.awssdk.services.pinpoint.model.UpdateEndpointResponse; import software.amazon.awssdk.services.pinpoint.model.GetEndpointRequest; import software.amazon.awssdk.services.pinpoint.model.GetEndpointResponse; import software.amazon.awssdk.services.pinpoint.model.PinpointException; import software.amazon.awssdk.services.pinpoint.model.EndpointDemographic; import software.amazon.awssdk.services.pinpoint.model.EndpointLocation; import software.amazon.awssdk.services.pinpoint.model.EndpointUser; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.List; import java.util.UUID; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Date; /** * 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 UpdateEndpoint { public static void main(String[] args) { final String usage = """ Usage: <appId> Where: appId - The ID of the application to create an endpoint for. """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String appId = args[0]; PinpointClient pinpoint = PinpointClient.builder() .region(Region.US_EAST_1) .build(); EndpointResponse response = createEndpoint(pinpoint, appId); System.out.println("Got Endpoint: " + response.id()); pinpoint.close(); } public static EndpointResponse createEndpoint(PinpointClient client, String appId) { String endpointId = UUID.randomUUID().toString(); System.out.println("Endpoint ID: " + endpointId); try { EndpointRequest endpointRequest = createEndpointRequestData(); UpdateEndpointRequest updateEndpointRequest = UpdateEndpointRequest.builder() .applicationId(appId) .endpointId(endpointId) .endpointRequest(endpointRequest) .build(); UpdateEndpointResponse updateEndpointResponse = client.updateEndpoint(updateEndpointRequest); System.out.println("Update Endpoint Response: " + updateEndpointResponse.messageBody()); GetEndpointRequest getEndpointRequest = GetEndpointRequest.builder() .applicationId(appId) .endpointId(endpointId) .build(); GetEndpointResponse getEndpointResponse = client.getEndpoint(getEndpointRequest); System.out.println(getEndpointResponse.endpointResponse().address()); System.out.println(getEndpointResponse.endpointResponse().channelType()); System.out.println(getEndpointResponse.endpointResponse().applicationId()); System.out.println(getEndpointResponse.endpointResponse().endpointStatus()); System.out.println(getEndpointResponse.endpointResponse().requestId()); System.out.println(getEndpointResponse.endpointResponse().user()); return getEndpointResponse.endpointResponse(); } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; } private static EndpointRequest createEndpointRequestData() { try { List<String> favoriteTeams = new ArrayList<>(); favoriteTeams.add("Lakers"); favoriteTeams.add("Warriors"); HashMap<String, List<String>> customAttributes = new HashMap<>(); customAttributes.put("team", favoriteTeams); EndpointDemographic demographic = EndpointDemographic.builder() .appVersion("1.0") .make("apple") .model("iPhone") .modelVersion("7") .platform("ios") .platformVersion("10.1.1") .timezone("America/Los_Angeles") .build(); EndpointLocation location = EndpointLocation.builder() .city("Los Angeles") .country("US") .latitude(34.0) .longitude(-118.2) .postalCode("90068") .region("CA") .build(); Map<String, Double> metrics = new HashMap<>(); metrics.put("health", 100.00); metrics.put("luck", 75.00); EndpointUser user = EndpointUser.builder() .userId(UUID.randomUUID().toString()) .build(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); // Quoted "Z" to indicate UTC, no timezone // offset String nowAsISO = df.format(new Date()); return EndpointRequest.builder() .address(UUID.randomUUID().toString()) .attributes(customAttributes) .channelType("APNS") .demographic(demographic) .effectiveDate(nowAsISO) .location(location) .metrics(metrics) .optOut("NONE") .requestId(UUID.randomUUID().toString()) .user(user) .build(); } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; } }
-
如需API詳細資訊,請參閱 參考 UpdateEndpoint中的 。 AWS SDK for Java 2.x API
-
如需開發人員指南和程式碼範例的完整清單 AWS SDK,請參閱 搭配 使用 Amazon Pinpoint AWS SDK。本主題也包含有關入門的資訊,以及先前SDK版本的詳細資訊。
SendMessages
Amazon Pinpoint SMS和 Voice API