timpham
timpham

Reputation: 565

Twilio using access token to send SMS

I keep reading in the doc that the access token can be used for services like Voice/Chat/Video, but I don't see anywhere mention sending SMS. Does Twilio exclude this functionality on purpose? i.e. my mobile app can acquire an access_token to send SMS

Upvotes: 1

Views: 1695

Answers (2)

philnash
philnash

Reputation: 73029

Twilio developer evangelist here.

Sending SMS messages uses the Twilio REST API and to use the REST API you always need your Account Sid. There are two ways you can authenticate to the API though.

You can either authenticate with your Account Sid and Auth Token, both found on your Twilio console. Then, using Node.js and the Twilio Node module, you would authenticate your client like this:

var client = require('twilio')(accountSid, authToken); 

Alternatively, you can generate an API Key and Secret from the Twilio console or you can create an API Key and Secret using the REST API. With those credentials you can also authenticate a client, but you still need to supply the Account Sid for the resource you want to use.

var client = require('twilio')(apiKey, apiSecret, { accountSid: accountSid }); 

The services that use access tokens are Video, Chat, Sync and the Programmable Voice SDKs. These are all services that have SDKs and run in the client side, either on iOS, Android or in the browser. They use access tokens because they allow the developer to authenticate users with Twilio without giving away the Auth Token or API Keys.

Upvotes: 4

abdulbari
abdulbari

Reputation: 6232

You can send the message via twilio module with relevant information

See the example below

// Twilio Credentials 
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; 
var authToken = 'your_auth_token'; 

//require the Twilio module and create a REST client 
var client = require('twilio')(accountSid, authToken); 

client.messages.create({ 
    to: "+15558675309", 
    from: "+15017250604", 
    body: "This is the ship that made the Kessel Run in fourteen parsecs?", 
    mediaUrl: "https://c1.staticflickr.com/3/2899/14341091933_1e92e62d12_b.jpg",  
}, function(err, message) { 
    console.log(message.sid); 
}); 

You can refer the sending-messages docs here

Upvotes: 0

Related Questions