Since Wit.AI API for android is deprecated i'm trying to use its http api to get a result in json from my wit.ai app. I don't know if it's possible but i'm trying to send an http request from my android app in this way:
public class MainActivity extends AppCompatActivity {
String addressM = "https://api.wit.ai/message?v=20160526";
String accessToken = "BODF5LOCAIPJZI37KTWQKELNUR26ZMDH";
String header = "Authorization: Bearer ";
String query = "q";
String message = "partita";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CallAPI runner = new CallAPI();
runner.execute(addressM);
}
public class CallAPI extends AsyncTask<String, String, String> {
public CallAPI() {
//set context variables if required
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
System.out.println("Running........................");
String urlString = params[0]; // URL to call
String resultToDisplay = "";
InputStream in = null;
try {
URL url = new URL(urlString);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty(header, accessToken);
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty(query, message);
in = new BufferedInputStream(urlConnection.getInputStream());
} catch (Exception e) {
System.out.println(e.getMessage());
return e.getMessage();
}
try {
resultToDisplay = IOUtils.toString(in, "UTF-8");
//to [convert][1] byte stream to a string
} catch (IOException e) {
e.printStackTrace();
}
return resultToDisplay;
}
@Override
protected void onPostExecute(String result) {
//Update the UI
}
}
I'm following this doc and i'm trying to send a simple "message request". So, i have to put a header in my url containing my auth token and then put my request in it. When sending my request i should get back a json and also an inbox message in my wit.ai app, but i'm not gettin anything (at the moment i don't really care for the json, but just for the inbox message to be sure my request has been sent). I copied the above code from another stack overflow question. I set my manifest correctly with internet permissions. Can someone help me?