Skip to content

Instantly share code, notes, and snippets.

@ismaelc
Created December 11, 2013 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ismaelc/7902947 to your computer and use it in GitHub Desktop.
Save ismaelc/7902947 to your computer and use it in GitHub Desktop.
Sample code on how to use Unirest-java to call Mashape APIs in your Android projects
public void sendMessage(View view) {
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
TextView txtView = (TextView) findViewById(R.id.textView1);
txtView.setText(message);
new CallMashapeAsync().execute(message);
}
private class CallMashapeAsync extends AsyncTask<String, Integer, HttpResponse<JsonNode>> {
protected HttpResponse<JsonNode> doInBackground(String... msg) {
HttpResponse<JsonNode> request = null;
try {
request = Unirest.get("https://webknox-question-answering.p.mashape.com/questions/answers?question=" + msg[0] + "&answerLookup=true&answerSearch=true")
.header("X-Mashape-Authorization", "<Insert your Mashape key here>")
.asJson();
} catch (UnirestException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return request;
}
protected void onProgressUpdate(Integer...integers) {
}
protected void onPostExecute(HttpResponse<JsonNode> response) {
String answer = response.getBody().toString();
TextView txtView = (TextView) findViewById(R.id.textView1);
txtView.setText(answer);
}
}
@rajashekharse
Copy link

I am getting NoClassDefFoundError: Failed resolution of: Ljavax/naming/ldap/LdapName;. Can you please help me to resolve this issue.

@ravidelcj
Copy link

Same error for me please help

@jigarfumakiya
Copy link

same error how to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment