java - Sending SMS using Sinch not working(Android) -


i using sinch , following tutorial, have code sending sms via java. once run getting filenotfoundexception error , following line:

{"errorcode":40100,"message":"authorization required"}

i have put phone number in e.164 format requested no avail. great!

 string phonenumber = "+1" + p.getphonenum();             log.e("adapteer", phonenumber);             string appkey = "app-key";             string appsecret = "app-secret";             string message = " hello! table has been cancelled. thank you.";              url url = new url("https://messagingapi.sinch.com/v1/sms/" + phonenumber);             httpurlconnection connection = (httpurlconnection)url.openconnection();             connection.setdooutput(true);             connection.setrequestmethod("post");             connection.setrequestproperty("content-type","application/json");              string usercredentials = "application\\" + appkey + ":" + appsecret;              byte[] encoded = base64.encodebase64(usercredentials.getbytes());             string basicauth = "basic " + new string(encoded);             connection.setrequestproperty("authorization", basicauth);              string postdata = "{\"message\":\"" + message + "\"}";             outputstream os = connection.getoutputstream();             os.write(postdata.getbytes());              stringbuilder response = new stringbuilder();             bufferedreader br = new bufferedreader(new inputstreamreader(connection.getinputstream()));              string line;             while((line= br.readline()) != null)                 response.append(line);              br.close();             os.close();              system.out.println(response.tostring()); 

if live key using need sign request, allow basic authorization on sandbox apps. more info https://www.sinch.com/tutorials/sign-requests-java/ , https://www.sinch.com/docs/sms/#authorization


Comments