0

我似乎无法更新用户“73”上预先存在的 UserAttributes。我不确定这种行为是否可以预期。

Map<String, List<String>> userAttributes = new HashMap<>();
userAttributes.put("Inference", Arrays.asList("NEGATIVE"));
userAttributes.put("Gender", Arrays.asList("M"));
userAttributes.put("ChannelPreference", Arrays.asList("EMAIL"));
userAttributes.put("TwitterHandle", Arrays.asList("Nutter"));
userAttributes.put("Age", Arrays.asList("435"));

EndpointUser endpointUser = new EndpointUser().withUserId("73");
endpointUser.setUserAttributes(userAttributes);

EndpointRequest endpointRequest = new EndpointRequest().withUser(endpointUser);

UpdateEndpointResult updateEndpointResult = pinpoint.updateEndpoint(new UpdateEndpointRequest()
    .withEndpointRequest(endpointRequest).withApplicationId("380c3902d4ds47bfb6f9c6749c6dc8bf").withEndpointId("a1fiy2gy+eghmsadj1vqew6+aa"));

System.out.println(updateEndpointResult.getMessageBody());
4

1 回答 1

0

@大卫韦伯斯特,

您可以使用以下 Java 代码片段更新 Amazon Pinpoint 终端节点的用户属性,我已测试该代码片段可以正常工作:

        public static void main(String[] args) throws IOException {


        // Try to update the endpoint.
        try {

            System.out.println("===============================================");

            System.out.println("Getting Started with Amazon Pinpoint"
                    +"using the AWS SDK for Java...");
            System.out.println("===============================================\n");


            // Initializes the Amazon Pinpoint client.
            AmazonPinpoint pinpointClient = AmazonPinpointClientBuilder.standard()
            .withRegion(Regions.US_EAST_1).build();


            // Creates a new user definition.
            EndpointUser jackchan = new EndpointUser().withUserId("73");

            // Assigns custom user attributes.
            jackchan.addUserAttributesEntry("name", Arrays.asList("Jack", "Chan"));
            jackchan.addUserAttributesEntry("Inference", Arrays.asList("NEGATIVE"));
            jackchan.addUserAttributesEntry("ChannelPreference", Arrays.asList("EMAIL"));
            jackchan.addUserAttributesEntry("TwitterHandle", Arrays.asList("Nutter"));
            jackchan.addUserAttributesEntry("gender", Collections.singletonList("M"));
            jackchan.addUserAttributesEntry("age", Collections.singletonList("435"));

            // Adds the user definition to the EndpointRequest that is passed to the Amazon Pinpoint client.
            EndpointRequest jackchanIphone = new EndpointRequest()
                    .withUser(jackchan);

            // Updates the specified endpoint with Amazon Pinpoint.
            UpdateEndpointResult result = pinpointClient.updateEndpoint(new UpdateEndpointRequest()
                    .withEndpointRequest(jackchanIphone)
                    .withApplicationId("4fd13a407f274f10b4ec06cbc71738bd")
                    .withEndpointId("095A8688-7D79-43CE-BDCE-7DF713332BC3"));

            System.out.format("Update endpoint result: %s\n", result.getMessageBody().getMessage());
        } catch (Exception ex) {
            System.out.println("EndpointUpdate Failed");
            System.err.println("Error message: " + ex.getMessage());
            ex.printStackTrace();
        }
    }
}

希望这可以帮助

于 2019-11-15T11:44:43.130 回答