# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'rubygems'
require 'twilio-ruby'
# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)
message = @client.messages
.create(
from: '+15557771212',
body: 'Ahoy! This message was sent from my Twilio phone number!',
to: '+15559991111'
)
puts message.body
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client
# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
message = client.messages \
.create(
from_='+15557771212',
body='Ahoy! This message was sent from my Twilio phone number!',
to='+15559991111'
)
print(message.body)
<?php
// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once '/path/to/vendor/autoload.php';
use Twilio\Rest\Client;
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);
$message = $twilio->messages
->create("+15559991111", // to
[
"from" => "+15557771212",
"body" => "Ahoy! This message was sent from my Twilio phone number!"
]
);
print($message->body);
// Download the helper library from https://www.twilio.com/docs/node/install
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.messages
.create({
from: '+15557771212',
body: 'Ahoy! This message was sent from my Twilio phone number!',
to: '+15559991111'
})
.then(message => console.log(message.body));
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
public class Example {
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");
public static void main(String[] args) {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Message message = Message.creator(
new com.twilio.type.PhoneNumber("+15559991111"),
new com.twilio.type.PhoneNumber("+15557771212"),
"Ahoy! This message was sent from my Twilio phone number!")
.create();
System.out.println(message.getBody());
}
}
// Download the helper library from https://www.twilio.com/docs/go/install
package main
import (
"fmt"
"github.com/twilio/twilio-go"
api "github.com/twilio/twilio-go/rest/api/v2010"
)
func main() {
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
client := twilio.NewRestClient()
params := &api.CreateMessageParams{}
params.SetFrom("+15557771212")
params.SetBody("Ahoy! This message was sent from my Twilio phone number!")
params.SetTo("+15559991111")
resp, err := client.Api.CreateMessage(params)
if err != nil {
fmt.Println(err.Error())
} else {
if resp.Body != nil {
fmt.Println(*resp.Body)
} else {
fmt.Println(resp.Body)
}
}
}
EXCLAMATION_MARK='!'
curl -X POST "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json" \
--data-urlencode "From=+15557771212" \
--data-urlencode "Body=Ahoy$EXCLAMATION_MARK This message was sent from my Twilio phone number$EXCLAMATION_MARK" \
--data-urlencode "To=+15559991111" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
// Install the C# / .NET helper library from twilio.com/docs/csharp/install
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
class Program
{
static void Main(string[] args)
{
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
TwilioClient.Init(accountSid, authToken);
var message = MessageResource.Create(
from: new Twilio.Types.PhoneNumber("+15557771212"),
body: "Ahoy! This message was sent from my Twilio phone number!",
to: new Twilio.Types.PhoneNumber("+15559991111")
);
Console.WriteLine(message.Body);
}
}
EXCLAMATION_MARK='!'
# Install the twilio-cli from https://twil.io/cli
twilio api:core:messages:create \
--from +15557771212 \
--body "Ahoy$EXCLAMATION_MARK This message was sent from my Twilio phone number$EXCLAMATION_MARK" \
--to +15559991111