UpdateEndpointÚselo con un AWS SDK - Amazon Pinpoint

Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.

UpdateEndpointÚselo con un AWS SDK

En el siguiente ejemplo de código se muestra cómo utilizarUpdateEndpoint.

Java
SDKpara Java 2.x
nota

Hay más información. GitHub Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de 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; } }
  • Para API obtener más información, consulte UpdateEndpointla AWS SDK for Java 2.x APIReferencia.

Para obtener una lista completa de guías para AWS SDK desarrolladores y ejemplos de código, consulteUso de Amazon Pinpoint con un AWS SDK. En este tema también se incluye información sobre cómo empezar y detalles sobre SDK las versiones anteriores.