/** * Example of making an outgoing call. * * @param client authenticated twilio client object * @param from the caller id of the phone call * @param to the phone number to be called * @param url the URL to execute when the called party answers */ private static void makeCallExample(TwilioRestClient client, String from, String to, String url) { // build map of post parameters Map<String, String> params = new HashMap<String, String>(); params.put("From", from); params.put("To", to); params.put("Url", url); TwilioRestResponse response; try { response = client.request( "/" + APIVERSION + "/Accounts/" + client.getAccountSid() + "/Calls", HttpMethod.POST, params); if (response.isError()) System.out.println( "Error making outgoing call: " + response.getHttpStatus() + "\n" + response.getResponseText()); else { System.out.println(response.getResponseText()); } } catch (TwilioRestException e) { e.printStackTrace(); } }
/** * Example of deleting a recording from your twilio account * * @param client authenticated twilio client object * @param RecordingSid the twilio Recording Id String you wish to delete */ private static void deleteRecordingsExample(TwilioRestClient client, String RecordingSid) { TwilioRestResponse response; try { response = client.request( "/" + APIVERSION + "/Accounts/" + client.getAccountSid() + "/Recordings/" + RecordingSid, HttpMethod.GET, null); if (response.isError()) System.out.println( "Error deleting recording: " + response.getHttpStatus() + "\n" + response.getResponseText()); else { System.out.println(response.getResponseText()); } } catch (TwilioRestException e) { e.printStackTrace(); } }
/** * Example of retrieving the Recordings for an account, filtered by call id * * @param client authenticated twilio client object * @param CallSid the twilio call ID string */ private static void getRecordingsExample(TwilioRestClient client, String CallSid) { // build map of parameters Map<String, String> params = new HashMap<String, String>(); params.put("CallSid", CallSid); TwilioRestResponse response; try { response = client.request( "/" + APIVERSION + "/Accounts/" + client.getAccountSid() + "/Recordings", HttpMethod.GET, params); if (response.isError()) System.out.println( "Error fetching recordings: " + response.getHttpStatus() + "\n" + response.getResponseText()); else { System.out.println(response.getResponseText()); } } catch (TwilioRestException e) { e.printStackTrace(); } }
public static void main(String[] args) { /* Twilio AccountSid and AuthToken */ String AccountSid = "AC31f00612c5c6f553a3f4a089e5012531"; String AuthToken = "dc40be9bcfdbc7677e5fff3ddbaf68ca"; /* Outgoing Caller ID previously validated with Twilio */ String CallerID = "+919173365243"; String ToCall = "+919471281973"; String Url = "http://twimlets.com/message?Message%5B0%5D=Hello%20from%20my%20java%20application.&Message%5B1%5D=http%3A%2F%2Fcom.twilio.music.electronica.s3.amazonaws.com%2Fteru_-_110_Downtempo_Electronic_4.mp3"; /* Instantiate a new Twilio Rest Client */ TwilioRestClient client = new TwilioRestClient(AccountSid, AuthToken, null); // build map of post parameters Map params = new HashMap(); params.put("From", CallerID); params.put("To", ToCall); params.put("Url", Url); TwilioRestResponse response; try { response = client.request( "/" + APIVERSION + "/Accounts/" + client.getAccountSid() + "/Calls", "POST", params); if (response.isError()) System.out.println( "Error making outgoing call: " + response.getHttpStatus() + "n" + response.getResponseText()); else { System.out.println(response.getResponseText()); } } catch (TwilioRestException e) { e.printStackTrace(); } }
/** * Example of retrieving recent error and warning notifications from your account * * @param client authenticated twilio client object */ private static void getNotificationsExample(TwilioRestClient client) { TwilioRestResponse response; try { response = client.request( "/" + APIVERSION + "/Accounts/" + client.getAccountSid() + "/Notifications", HttpMethod.GET, null); if (response.isError()) System.out.println( "Error fetching recent notifications: " + response.getHttpStatus() + "\n" + response.getResponseText()); else { System.out.println(response.getResponseText()); } } catch (TwilioRestException e) { e.printStackTrace(); } }