【问题标题】:Amazon SNS: How to get EndpointArn by token(registrationId) using amazon .net sdk?Amazon SNS:如何使用 amazon .net sdk 通过令牌(registrationId)获取 EndpointArn?
【发布时间】:2014-04-25 10:23:30
【问题描述】:

我正在尝试使用 aws .net sdk 通过注册 ID 获取 EndpointArn。但我找不到一个很好的方法来做到这一点。

我的第一次尝试是使用相同的registrationId 运行CreatePlatformEndpointRequest,该registrationId 之前已注册到SNS 应用程序,由客户端(android)发送。通过这种方式,aws api 为您提供了此注册 ID 的 EndpointArn。

Amazon: CreatePlatformEndpoint 动作是幂等的,所以如果请求者 已经拥有一个具有相同设备令牌和属性的端点, 返回该端点的 ARN,而不创建新的端点。

但是,如果您在需要发送相同的用户数据以获取此注册 ID 的端点 arn 之前存储了一些内容到 CustomUserData,否则您会收到如下所示的异常。

无效参数:令牌原因:端点 {我的端点 ARN} 已经存在同一个Token,但属性不同。

我想我将在没有用户数据的情况下使用 CreatePlatformEndpoint(),当我需要 Endpoint Arn 作为registrationId 时,我将仅使用此注册 ID 运行 CreatePlatFormEndpoint。

有没有比上面的解决方案更好的通过令牌获取 EndpointArn 的方法?

谢谢。

【问题讨论】:

  • 仅供参考:我只是做出这个决定......而且我继续遇到同样的错误。我将“”作为用户数据发送,并且继续返回错误:s
  • 我也面临同样的问题。不知道出了什么问题?
  • 我们也有同样的问题。查看我们的问题:stackoverflow.com/questions/22227262/…
  • 可以从异常信息中获取端点的ARN,SNS返回已经存在的端点的ARN
  • @babur 说真的,这是一个糟糕的解决方案。如果错误信息的格式发生变化怎么办?

标签: .net amazon-web-services push-notification google-cloud-messaging amazon-sns


【解决方案1】:

我们所做的是将 CreatePlatformEndpoint 返回的端点 ARN 存储在我们的应用程序数据库中。如果我们已经有一个给定设备注册 ID 的端点 ARN 关联,那么我们调用

getEndpointAttributes 从我们的数据库传入端点 arn。如果返回结果,则检查端点是否标记为启用,如果没有,则调用 setEndpointAttributes 并将键“启用”设置为“真”。

不幸的是,Amazaon API 似乎没有提供“findBy”方法来通过“CustomUserData”或“Token”进行查找,并且只有“list”方法可以列出所有现有端点,这对于大多数应用程序来说是不够的,如果可能有数千或数百万个条目。就好像 API 只是为了满足 Amazon 控制台 UI 用例而编写的。

另外,请参阅 Amazon 文档以了解 API 请求和响应示例

http://docs.aws.amazon.com/sns/latest/api/API_GetEndpointAttributes.html http://docs.aws.amazon.com/sns/latest/api/API_SetEndpointAttributes.html

【讨论】:

    【解决方案2】:

    根据https://mobile.awsblog.com/post/Tx223MJB0XKV9RU/Mobile-token-management-with-Amazon-SNS 的 AWS 博客,他们还建议应用程序端存储 ARN。

    retrieve the latest token from the mobile OS
    if (endpoint arn not stored)
        # first time registration
        call CreatePlatformEndpoint
        store returned endpoint arn
    endif
    
    call GetEndpointAttributes on the endpoint arn 
    
    if (getting attributes encountered NotFound exception)
        #endpoint was deleted 
        call CreatePlatformEndpoint
        store returned endpoint arn
    else 
        if (token in endpoint does not match latest) or 
            (GetEndpointAttributes shows endpoint as disabled)
            call SetEndpointAttributes to set the 
                         latest token and enable the endpoint
        endif
    endif
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-25
      • 1970-01-01
      • 2015-10-12
      • 2014-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多