Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 151 lines (116 sloc) 6.381 kb
0ba5457 @carlosdp Add Travis CI build status to README
carlosdp authored
1 [![Build Status](https://travis-ci.org/twilio/twilio-java.png?branch=master)](https://travis-ci.org/twilio/twilio-java)
2
c01ba9e Bump version to 3.3.16
Kevin Burke authored
3 # Installing
7c197bb adding v3.0 files
Frank Stratton authored
4
c01ba9e Bump version to 3.3.16
Kevin Burke authored
5 TwilioJava is now using Maven. At present the jars *are* available from a public [maven](http://maven.apache.org/download.html) repository.
d8c9618 @ChristerF Further cleanup and doc
ChristerF authored
6
7 Use the following dependency in your project:
0078436 @ChristerF fixing readme
ChristerF authored
8
9 <dependency>
10 <groupId>com.twilio.sdk</groupId>
3fff591 @andrewmbenton bring readme inline with pom.xml
andrewmbenton authored
11 <artifactId>twilio-java-sdk</artifactId>
09eaf29 @skimbrel Bump to 4.0.1
skimbrel authored
12 <version>4.0.1</version>
0078436 @ChristerF fixing readme
ChristerF authored
13 <scope>compile</scope>
14 </dependency>
15
12e9d6a @eanderle update README.md to reflect central Maven repo
eanderle authored
16 If you want to compile it yourself, here's how:
17
2a64e33 remove trailing period
Kevin Burke authored
18 $ git clone git@github.com:twilio/twilio-java
c01ba9e Bump version to 3.3.16
Kevin Burke authored
19 $ cd twilio-java
12e9d6a @eanderle update README.md to reflect central Maven repo
eanderle authored
20 $ mvn install # Requires maven, download from http://maven.apache.org/download.html
21
22 This will also build the javadoc in `twilio-java/target/apidocs`. You can open the
23 index.html located there to view it locally.
24
75621b6 clean up typos
Brett Gerry authored
25 Pre-built jars are available [here](http://search.maven.org/#browse%7C-1416163511). Select the directory for
374574c link to correct maven directory containing jar files
Brett Gerry authored
26 the latest version and download one of these jar files:
291d3f1 update links to jars
Frank Stratton authored
27
3b1550e Bumping version to 4.0.0
Matthew Nowack authored
28 * twilio-java-sdk-4.x.x-with-dependencies.jar
29 * twilio-java-sdk-4.x.x.jar -- use this if you have issues with conflicting jars in your project. You'll need to include versions of the dependencies yourself. See the [pom.xml](https://github.com/twilio/twilio-java/blob/master/pom.xml) file in [twilio-java](https://github.com/twilio/twilio-java) for the list of libraries.
7c197bb adding v3.0 files
Frank Stratton authored
30
31 You can view the javadocs for this project at:
f6d6ac0 update links
Kevin Burke authored
32 [http://twilio.github.io/twilio-java](http://twilio.github.io/twilio-java)
7c197bb adding v3.0 files
Frank Stratton authored
33
34 # Examples
35
c01ba9e Bump version to 3.3.16
Kevin Burke authored
36 Here are some examples (also found in [TwilioRestExamples.java](https://github.com/twilio/twilio-java/blob/master/src/main/java/com/twilio/sdk/examples/RestExamples.java) )
7c197bb adding v3.0 files
Frank Stratton authored
37
d4064a2 @gbin added java syntax coloring
gbin authored
38 ```java
9b188a9 @gbin removed extraneous tab in the example
gbin authored
39 package com.twilio.sdk.examples;
40
41 import java.util.HashMap;
42 import java.util.Iterator;
43 import java.util.List;
5e580cd @akshar100 Update README.md
akshar100 authored
44 import java.util.ArrayList;
9b188a9 @gbin removed extraneous tab in the example
gbin authored
45 import java.util.Map;
46
47 import com.twilio.sdk.TwilioRestClient;
48 import com.twilio.sdk.TwilioRestException;
49 import com.twilio.sdk.TwilioRestResponse;
50 import com.twilio.sdk.resource.factory.CallFactory;
5e580cd @akshar100 Update README.md
akshar100 authored
51 import com.twilio.sdk.resource.factory.SmsFactory;
9b188a9 @gbin removed extraneous tab in the example
gbin authored
52 import com.twilio.sdk.resource.instance.Account;
53 import com.twilio.sdk.resource.instance.AvailablePhoneNumber;
54 import com.twilio.sdk.resource.instance.Call;
55 import com.twilio.sdk.resource.instance.Conference;
56 import com.twilio.sdk.resource.instance.Participant;
57 import com.twilio.sdk.resource.list.AccountList;
58 import com.twilio.sdk.resource.list.AvailablePhoneNumberList;
59 import com.twilio.sdk.resource.list.ParticipantList;
60 import com.twilio.sdk.verbs.TwiMLException;
ef7ef17 @dougblack update readme
dougblack authored
61 import org.apache.http.NameValuePair;
62 import org.apache.http.message.BasicNameValuePair;
9b188a9 @gbin removed extraneous tab in the example
gbin authored
63
64 public class Example {
65
66 public static final String ACCOUNT_SID = "AC.....";
67 public static final String AUTH_TOKEN = ".......";
68
69 public static void main(final String[] args) throws TwilioRestException, TwiMLException {
70
71 // Create a rest client
72 final TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
73
74 // Get the main account (The one we used to authenticate the client)
75 final Account mainAccount = client.getAccount();
76
77 // Get all accounts including sub accounts
78 AccountList accountList = client.getAccounts();
79
80 // All lists implement an iterable interface, you can use the foreach
81 // syntax on them
82 for (final Account a : accountList) {
83 System.out.println(a.getFriendlyName());
84 }
85
86 // You can also iterate manually...
87 final Iterator<Account> itr = accountList.iterator();
88 while (itr.hasNext()) {
89 final Account a = itr.next();
90 System.out.println(a.getFriendlyName());
91 }
92
93 // You can also get just the first page of data
94 accountList = client.getAccounts();
95 final List<Account> accounts = accountList.getPageData();
96
97 // Make a call
98 final CallFactory callFactory = mainAccount.getCallFactory();
99 final Map<String, String> callParams = new HashMap<String, String>();
100 callParams.put("To", "5105551212"); // Replace with a valid phone number
101 callParams.put("From", "(510) 555-1212"); // Replace with a valid phone number in your account
102 callParams.put("Url", "http://demo.twilio.com/welcome/voice/");
103 final Call call = callFactory.create(callParams);
104 System.out.println(call.getSid());
105
6ef3233 @kwhinnery indicate version requirement
kwhinnery authored
106 // Send an SMS (Requires version 3.4+)
5e580cd @akshar100 Update README.md
akshar100 authored
107 final SmsFactory messageFactory = mainAccount.getSmsFactory();
73ef4ba @AlekSi Fix error in example
AlekSi authored
108 final List<NameValuePair> messageParams = new ArrayList<NameValuePair>();
ef7ef17 @dougblack update readme
dougblack authored
109 messageParams.add(new BasicNameValuePair("To", "5105551212")); // Replace with a valid phone number
110 messageParams.add(new BasicNameValuePair("From", "(510) 555-1212")); // Replace with a valid phone number in your account
111 messageParams.add(new BasicNameValuePair("Body", "This is a test message!"));
112 messageFactory.create(messageParams);
9b188a9 @gbin removed extraneous tab in the example
gbin authored
113
114 // Search for available phone numbers & then buy a random phone number
115 final AvailablePhoneNumberList phoneNumbers = mainAccount.getAvailablePhoneNumbers();
116 final List<AvailablePhoneNumber> list = phoneNumbers.getPageData();
117
118 // Buy the first number returned
119 final Map<String, String> params = new HashMap<String, String>();
120 params.put("PhoneNumber", list.get(0).getPhoneNumber());
121 params.put("VoiceUrl", "http://demo.twilio.com/welcome/voice/");
122 mainAccount.getIncomingPhoneNumberFactory().create(params);
123
124 // View a conference using its sid
125 final Conference c = mainAccount.getConference("CA12345...");
126 final ParticipantList participants = c.getParticipants();
127
128 for (final Participant p : participants) {
129 // Randomly mute or kick each participant
130 if (Math.random() > 0.5) {
131 p.mute();
132 } else {
133 p.kick();
134 }
135 }
136
137 // Make a raw HTTP request to the api... note, this is deprecated style
138 final TwilioRestResponse resp = client.request("/2010-04-01/Accounts", "GET", null);
139 if (!resp.isError()) {
140 System.out.println(resp.getResponseText());
141 }
142 }
143 }
7c197bb adding v3.0 files
Frank Stratton authored
144 ```
4fd3920 @skimbrel Add help pointers to README.md
skimbrel authored
145
146 # Getting help
147
148 If you need help installing or using the library, please contact Twilio Support at help@twilio.com first. Twilio's Support staff are well-versed in all of the Twilio Helper Libraries, and usually reply within 24 hours.
149
150 If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!
Something went wrong with that request. Please try again.