Search code examples
androidpostionic-frameworkpushrest-client

Unable to Authenticate Ionic push


I try to send a request with RestClient to https://push.ionic.io/api/v1/push. I'm following all the instructions said http://docs.ionic.io/docs/push-api-examples. I change my private key to base64 with www.base64encode.org but at the end the return is:

{
   "result": "error",
   "message": "Unable to Authenticate"
}

here is the json a send :

{
  "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"
      }
    }
  }
}

Edit :

    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);
}

I am using play framework to do http request


Solution

  • To solved the probleme i added (:) and also the APP_ID has to be in lowercase like : dr2h3525