如何使用电子邮件protocl获取sns令牌

时间:2015-05-13 13:50:03

标签: java amazon-sns

您好,任何人都知道如何获取sns电子邮件端点的访问令牌。请你帮忙。没有任何关于此的教程。这是一个试图将通知推送到我的客户端电子邮件的网络应用

public class EmailNotifications {

private static final String accessKey = "";
private static final String secretAccess ="";


public static void SignUP(String email, String Topic){
    AmazonSNSClient snsClient = new AmazonSNSClient(new BasicAWSCredentials(accessKey, secretAccess));
    snsClient.setRegion(Region.getRegion(Regions.US_WEST_1));

    //create a Topic
    CreateTopicRequest createTopicRequest = new CreateTopicRequest().withName(Topic);
    CreateTopicResult createTopicResult = snsClient.createTopic(createTopicRequest);

    //subscribes to a topic
    SubscribeRequest subscribeRequest = new SubscribeRequest().withTopicArn(createTopicResult.getTopicArn())
                                                                .withProtocol("email").withEndpoint(email);
   /*SubscribeResult rr= */snsClient.subscribe(subscribeRequest);



   ConfirmSubscriptionRequest confirmSubscriptionRequest = new ConfirmSubscriptionRequest().withTopicArn(createTopicResult.getTopicArn());
   // ConfirmSubscriptionResult confirmSubscriptionResult = snsClient.
    //confirmSubscriptionResult.getSubscriptionArn();
    String token = confirmSubscriptionRequest.getToken();
    ConfirmSubscriptionResult confirmSubscriptionResult = snsClient.confirmSubscription(createTopicResult.getTopicArn(), token);

    //PublishRequest
  }
}

1 个答案:

答案 0 :(得分:1)

您有API here仔细阅读。

验证sns最终使用confirmSubscription

  

通过验证先前订阅操作发送到端点的令牌来验证端点所有者接收消息的意图。

this question也可以提供帮助。