我正在尝试注册我的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);
您有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()
请按照以下步骤设置您的地区:
//Replace with whatever region your app is
pushClient.setRegion(Region.getRegion(Regions.US_WEST_2));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句