Rya*_*yan 2 android amazon-sns
我正在尝试注册我的Android设备以接收推送通知,但亚马逊服务器返回错误,说它无法找到我的PlatformApplicationArn.我使用他们的sdk设置它,但它似乎没有找到它.
这是错误:AWS错误消息:无效参数:PlatformApplicationArn原因:没有必需参数的值
这是发送它的代码:
String platformApplicationArn = "arn:aws:sns:us-east-1:897955111111:app/GCM/com.myapp";
AWSCredentials awsCredentials = new BasicAWSCredentials("XXXXXXXX", "XXXXXXXXXXXXXXXXXXXXX");
pushClient = new AmazonSNSClient(awsCredentials);
CreatePlatformEndpointRequest createPlatformEndpointRequest = new CreatePlatformEndpointRequest();
String customPushData = "my custom data";
CreatePlatformEndpointRequest platformEndpointRequest = new CreatePlatformEndpointRequest();
platformEndpointRequest.setCustomUserData(customPushData);
platformEndpointRequest.setToken(pushNotificationRegId);
platformEndpointRequest.setPlatformApplicationArn(platformApplicationArn);
CreatePlatformEndpointResult result = pushClient.createPlatformEndpoint(createPlatformEndpointRequest);
Run Code Online (Sandbox Code Playgroud)
您有2个实例,CreatePlatformEndpointRequest并且您将令牌和applicationArn设置为一个,但是将另一个用于SNSClient请求,因此它缺少必需的参数.
String platformApplicationArn = "arn:aws:sns:us-east-1:897955111111:app/GCM/com.myapp";
AWSCredentials awsCredentials = new BasicAWSCredentials("XXXXXXXX", "XXXXXXXXXXXXXXXXXXXXX");
AmazonSNSClient pushClient = new AmazonSNSClient(awsCredentials);
//probably no need for this
String customPushData = "my custom data";
CreatePlatformEndpointRequest platformEndpointRequest = new CreatePlatformEndpointRequest();
platformEndpointRequest.setCustomUserData(customPushData);
platformEndpointRequest.setToken(pushNotificationRegId);
platformEndpointRequest.setPlatformApplicationArn(platformApplicationArn);
CreatePlatformEndpointResult result = pushClient.createPlatformEndpoint(platformEndpointRequest);
Run Code Online (Sandbox Code Playgroud)
此外,除非您的SNS应用区域为US_EAST_1,否则我发现您必须手动设置区域,否则您将收到不匹配的区域错误响应,因此在调用之前createPlatformEndpoint()设置您的区域如下:
//Replace with whatever region your app is
pushClient.setRegion(Region.getRegion(Regions.US_WEST_2));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6388 次 |
| 最近记录: |