Amazon SNS:如何使用 amazon .net sdk 通过令牌(registrationId)获取 EndpointArn? [英] Amazon SNS: How to get EndpointArn by token(registrationId) using amazon .net sdk?

查看:25
本文介绍了Amazon SNS:如何使用 amazon .net sdk 通过令牌(registrationId)获取 EndpointArn?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to get EndpointArn by registration id using aws .net sdk. But i couldn't find a nice way to do it.

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

My first attempt was running CreatePlatformEndpointRequest with the same registrationId, which is registered to SNS Application before, sent by the client(android). With this way, aws api gives you the EndpointArn for this registration id.

亚马逊:CreatePlatformEndpoint 操作是幂等的,所以如果请求者已经拥有具有相同设备令牌和属性的端点,返回该终端节点的 ARN 而不创建新终端节点.

Amazon: The CreatePlatformEndpoint action is idempotent, so if the requester already owns an endpoint with the same device token and attributes, that endpoint's ARN is returned without creating a new endpoint.

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

But if you stored something to CustomUserData before you need to send the same user data to get endpoint arn for this registration id, otherwise you get an exception like below.

无效参数:令牌原因:端点{我的端点 ARN}已存在,具有相同的 Token,但具有不同的属性.

Invalid parameter: Token Reason: Endpoint {My Endpoint ARN} already exists with the same Token, but different attributes.

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

I think i am going to use CreatePlatformEndpoint() without user data and when i need Endpoint Arn for a registrationId i will run CreatePlatFormEndpoint only with this registration id.

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

Is there another way to get EndpointArn by token better than the solution above ?

谢谢.

推荐答案

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

What we did is store the endpoint ARN returned from CreatePlatformEndpoint in our application database. If we already have an endpoint ARN association for a given device registration id, we then call

getEndpointAttributes 从我们的数据库中传入端点 arn.如果返回结果,我们然后检查端点是否标记为启用,如果没有,则调用 setEndpointAttributes 并将键启用"设置为true".

getEndpointAttributes passing in the endpoint arn from our database. If a result is returned, we then check if the endpoint is marked enabled and if not then call setEndpointAttributes and set key "Enabled" to "true".

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

Unfortunately it doesn't look like Amazaon API offers a "findBy" method to look up by "CustomUserData" or "Token" and only has "list" methods that list all the existing endpoints which for most applications will not suffice if there are potentially thousands or millions of entries. It is almost as if API was written only to satisfy the Amazon Console UI use cases.

此外,请参阅 Amazon 文档以获取 API 请求和响应示例

Also, see Amazon docs for example API requests and responses

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

这篇关于Amazon SNS:如何使用 amazon .net sdk 通过令牌(registrationId)获取 EndpointArn?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆