File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5+ <modelVersion >4.0.0</modelVersion >
6+
7+ <groupId >com.baeldung.twilio</groupId >
8+ <artifactId >sms</artifactId >
9+ <version >1.0-SNAPSHOT</version >
10+
11+ <properties >
12+ <maven .compiler.source>1.8</maven .compiler.source>
13+ <maven .compiler.target>1.8</maven .compiler.target>
14+ </properties >
15+
16+ <dependencies >
17+ <dependency >
18+ <groupId >com.twilio.sdk</groupId >
19+ <artifactId >twilio</artifactId >
20+ <version >7.20.0</version >
21+ </dependency >
22+ </dependencies >
23+
24+ </project >
Original file line number Diff line number Diff line change 1+ import com .twilio .Twilio ;
2+ import com .twilio .rest .api .v2010 .account .Message ;
3+ import com .twilio .type .PhoneNumber ;
4+
5+ public class TwilioSmsExample {
6+ // Find your Account Sid and Token at twilio.com/console
7+ public static final String ACCOUNT_SID = "YOUR_ACCOUNT_SID" ;
8+ public static final String AUTH_TOKEN = "YOUR_ACCOUNT_TOKEN" ;
9+
10+ // Create a phone number in the Twilio console
11+ public static final String TWILIO_NUMBER = "+13334445555" ;
12+
13+ public static void main (String [] args ) {
14+ Twilio .init (ACCOUNT_SID , AUTH_TOKEN );
15+ Message message = Message .creator (
16+ new PhoneNumber ("+12227779999" ),
17+ new PhoneNumber (TWILIO_NUMBER ),
18+ "Sample Twilio SMS using Java" )
19+ .create ();
20+
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ import com .twilio .Twilio ;
2+ import com .twilio .converter .Promoter ;
3+ import com .twilio .rest .api .v2010 .account .Message ;
4+ import com .twilio .type .PhoneNumber ;
5+
6+ import java .net .URI ;
7+
8+ public class TwilioSmsMediaExample {
9+ // Find your Account Sid and Token at twilio.com/console
10+ public static final String ACCOUNT_SID = "YOUR_ACCOUNT_SID" ;
11+ public static final String AUTH_TOKEN = "YOUR_ACCOUNT_TOKEN" ;
12+
13+ // Create a phone number in the Twilio console
14+ public static final String TWILIO_NUMBER = "+13334445555" ;
15+
16+ public static void main (String [] args ) {
17+ Twilio .init (ACCOUNT_SID , AUTH_TOKEN );
18+ Message message = Message .creator (
19+ new PhoneNumber ("+12227779999" ),
20+ new PhoneNumber (TWILIO_NUMBER ),
21+ "Sample Twilio MMS using Java" )
22+ .setMediaUrl (
23+ Promoter .listOfOne (
24+ URI .create ("http://www.baeldung.com/wp-content/uploads/2017/10/icon-javaseries-home.png" )))
25+ .create ();
26+ }
27+ }
Original file line number Diff line number Diff line change 1+ import com .google .common .util .concurrent .FutureCallback ;
2+ import com .google .common .util .concurrent .Futures ;
3+ import com .google .common .util .concurrent .ListenableFuture ;
4+ import com .twilio .Twilio ;
5+ import com .twilio .base .ResourceSet ;
6+ import com .twilio .rest .api .v2010 .account .Message ;
7+
8+ public class TwilioSmsStatusAsyncExample {
9+ // Find your Account Sid and Token at twilio.com/console
10+ public static final String ACCOUNT_SID = "YOUR_ACCOUNT_SID" ;
11+ public static final String AUTH_TOKEN = "YOUR_AUTH_TOKEN" ;
12+
13+ // Create a phone number in the Twilio console
14+ public static final String TWILIO_NUMBER = "+13334445555" ;
15+
16+ public static void main (String [] args ) {
17+
18+ Twilio .init (ACCOUNT_SID , AUTH_TOKEN );
19+ ListenableFuture <ResourceSet <Message >> future = Message .reader ().readAsync ();
20+ Futures .addCallback (
21+ future ,
22+ new FutureCallback <ResourceSet <Message >>() {
23+ public void onSuccess (ResourceSet <Message > messages ) {
24+ for (Message message : messages ) {
25+ System .out .println (message .getSid () + " : " + message .getStatus ());
26+ }
27+ }
28+
29+ public void onFailure (Throwable t ) {
30+ System .out .println ("Failed to get message status: " + t .getMessage ());
31+ }
32+ });
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ import com .twilio .Twilio ;
2+ import com .twilio .base .ResourceSet ;
3+ import com .twilio .rest .api .v2010 .account .Message ;
4+ import com .twilio .type .PhoneNumber ;
5+
6+ public class TwilioSmsStatusExample {
7+ // Find your Account Sid and Token at twilio.com/console
8+ public static final String ACCOUNT_SID = "YOUR_ACCOUNT_SID" ;
9+ public static final String AUTH_TOKEN = "YOUR_ACCOUNT_TOKEN" ;
10+
11+ // Create a phone number in the Twilio console
12+ public static final String TWILIO_NUMBER = "+13334445555" ;
13+
14+ public static void main (String [] args ) {
15+
16+ Twilio .init (ACCOUNT_SID , AUTH_TOKEN );
17+ ResourceSet <Message > messages = Message .reader ().read ();
18+ for (Message message : messages ) {
19+ System .out .println (message .getSid () + " : " + message .getStatus ());
20+ }
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments