我正在尝试注册我的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);
答案 0 :(得分:8)
您有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);
此外,除非您的SNS应用区域为US_EAST_1,否则我发现您必须手动设置区域,否则您将收到不匹配的区域错误响应,因此在致电createPlatformEndpoint()
之前,请按照以下方式设置您的区域:< / p>
//Replace with whatever region your app is
pushClient.setRegion(Region.getRegion(Regions.US_WEST_2));