我正在尝试将Amazon Push Notifications集成到我的iPhone应用程序中。我确实按照这里提供的教程进行了操作。
创建Platform EndPoint时出现此错误。 (似乎身份池的权限问题???)
public class MainActivity extends Activity {
private ProgressDialog pDialog;
String result;
StringBuilder sb;
InputStream is;
JSONArray jArray;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new task().execute();
}
class task extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
Log.i("doing", "back");
ArrayList<NameValuePair> nameValuePairs =
new ArrayList<NameValuePair>();
// http post
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://XXXXXXXXXX/abcd.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection" + e.toString());
}
// convert response to string
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, "iso-8859-1"), 8);
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line = "0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
Log.i("Result", "Json" + result);
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
String name;
try {
jArray = new JSONArray(result);
JSONObject json_data = null;
for (int i = 0; i < jArray.length(); i++) {
json_data = jArray.getJSONObject(i);
String gid = json_data.getString("gid");
String district = json_data.getString("district");
Log.i("LOG", "resultttttttt" + gid + " " + district);
}
} catch (JSONException e1) {
Toast.makeText(getBaseContext(), "No Data Found",
Toast.LENGTH_LONG).show();
} catch (ParseException e1) {
e1.printStackTrace();
} catch (NullPointerException e) {
// TODO: handle exception
Toast.makeText(getBaseContext(), "No Data Found",
Toast.LENGTH_LONG).show();
}
return null;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if (pDialog.isShowing())
pDialog.dismiss();
}
}
}
完整信息:
CognitoIdentityCredentials is not authorized to perform: SNS:CreatePlatformEndpoint
代码
Error: Error Domain=com.amazonaws.AWSSNSErrorDomain Code=4 "The operation couldn’t be completed. (com.amazonaws.AWSSNSErrorDomain error 4.)" UserInfo=0x165dcef0 {Type=Sender, Message=User: arn:aws:sts::290442422498:assumed-role/Cognito_Laugh_DevUnauth_Role/CognitoIdentityCredentials is not authorized to perform: SNS:CreatePlatformEndpoint on resource: arn:aws:sns:us-east-1:290442422498:app/APNS_SANDBOX/Laugh, __text=(
"\n ",
"\n ",
"\n ",
"\n "
), Code=AuthorizationError}
}
答案 0 :(得分:17)
问题出在AWS SNS配置中。我们需要添加&#34; SNS:CreatePlatformEndpoint&#34; Auth和Unauth角色的政策
答案 1 :(得分:9)
您可以在AmazonSNSFullAccess
- &gt; Roles
下添加attach policy
。