无法验证离子推送
Unable to Authenticate Ionic push
我尝试使用 RestClient 向 https://push.ionic.io/api/v1/push. I'm following all the instructions said http://docs.ionic.io/docs/push-api-examples 发送请求。我用 www.base64encode.org 将私钥更改为 base64,但最后 return 是:
{
"result": "error",
"message": "Unable to Authenticate"
}
这里是 json 发送:
{
"tokens":"fRB8B55UKS8:APA91bHjfNL7TJuAFzJKEQHSb4717__Ezz-nNvhSTgBdzuBhLz70P95S7lXDb46jfA6pZE-OWOdL-RCBBX0tnDCB7NZR0Og4YXcX5kvWlURwDfYfsH361ImJsdPap42JUr-wnkNqj0St",
"notification":{
"alert":"Hello World!",
"ios":{
"badge":1,
"sound":"ping.aiff",
"expiry": 1423238641,
"priority": 10,
"contentAvailable": 1,
"payload":{
"key1":"value",
"key2":"value"
}
},
"android":{
"collapseKey":"foo",
"delayWhileIdle":true,
"timeToLive":300,
"payload":{
"key1":"value",
"key2":"value"
}
}
}
}
编辑:
public static void push(String notification){
String str = "{\"tokens\": [\"fRB8B55UKS8:APA91bHjfNL7TJuAFzJKEQHSb4717__Ezz-nNvhSTgBdzuBhLz70P95S7lXDb46jfA6pZE-OWOdL-RCBBX0tnDCB7NZR0Og4YXcX5kvWlURwDfYfsH361ImJsdPap42JUr-wnkNqj0St\"],\"production\": true, \"notification\":{ \"alert\":\"azr\", \"title\": \"TOTO\", \"android\": {\"payload\": {}}, \"ios\": {\"payload\": {}}}}";
Promise<String> promise = WS.url(PUSH_URL)
.setContentType("application/json")
.setHeader("X-Ionic-Application-Id", APP_ID)
.setHeader("Authorization", "Basic " + new String(SECRET_ENCODED))
.post(str)
.map(
new Function<WS.Response, String>() {
public String apply(WS.Response response) {
String result = response.getBody();
return result;
}
});
String boo;
long timeout = 2000l;
boo = promise.get(timeout);
}
我正在使用 play 框架做 http 请求
为了解决问题,我添加了 (:) 并且 APP_ID 必须小写,例如:dr2h3525
我尝试使用 RestClient 向 https://push.ionic.io/api/v1/push. I'm following all the instructions said http://docs.ionic.io/docs/push-api-examples 发送请求。我用 www.base64encode.org 将私钥更改为 base64,但最后 return 是:
{
"result": "error",
"message": "Unable to Authenticate"
}
这里是 json 发送:
{
"tokens":"fRB8B55UKS8:APA91bHjfNL7TJuAFzJKEQHSb4717__Ezz-nNvhSTgBdzuBhLz70P95S7lXDb46jfA6pZE-OWOdL-RCBBX0tnDCB7NZR0Og4YXcX5kvWlURwDfYfsH361ImJsdPap42JUr-wnkNqj0St",
"notification":{
"alert":"Hello World!",
"ios":{
"badge":1,
"sound":"ping.aiff",
"expiry": 1423238641,
"priority": 10,
"contentAvailable": 1,
"payload":{
"key1":"value",
"key2":"value"
}
},
"android":{
"collapseKey":"foo",
"delayWhileIdle":true,
"timeToLive":300,
"payload":{
"key1":"value",
"key2":"value"
}
}
}
}
编辑:
public static void push(String notification){
String str = "{\"tokens\": [\"fRB8B55UKS8:APA91bHjfNL7TJuAFzJKEQHSb4717__Ezz-nNvhSTgBdzuBhLz70P95S7lXDb46jfA6pZE-OWOdL-RCBBX0tnDCB7NZR0Og4YXcX5kvWlURwDfYfsH361ImJsdPap42JUr-wnkNqj0St\"],\"production\": true, \"notification\":{ \"alert\":\"azr\", \"title\": \"TOTO\", \"android\": {\"payload\": {}}, \"ios\": {\"payload\": {}}}}";
Promise<String> promise = WS.url(PUSH_URL)
.setContentType("application/json")
.setHeader("X-Ionic-Application-Id", APP_ID)
.setHeader("Authorization", "Basic " + new String(SECRET_ENCODED))
.post(str)
.map(
new Function<WS.Response, String>() {
public String apply(WS.Response response) {
String result = response.getBody();
return result;
}
});
String boo;
long timeout = 2000l;
boo = promise.get(timeout);
}
我正在使用 play 框架做 http 请求
为了解决问题,我添加了 (:) 并且 APP_ID 必须小写,例如:dr2h3525