REST API: ネットワークトラバーサルサービストークン

ネットワークトラバーサルサービストークンは、WebRTC クライアントと VoIP クライアントから TURN リソースにアクセスできるようにする短時間有効なクレデンシャルです。これは、クライアントサイドの環境でクレデンシャルを公開することなく、ウェブブラウザまたはモバイルアプリでコミュニケーションセッションを作成する安全な方法です。不正な利用を防止するため、すべてのトークンには有効期限があります。有効期限は 24 時間(デフォルト値)まで設定できますが、アプリケーションではできるだけ短くする必要があります。

トークンリストリソース

リソース URI

/2010-04-01/Accounts/{AccountSid}/Tokens

リソースのプロパティ

トークンインスタンスリソースは下記のプロパティを持ちます

プロパティ 説明
Username トークンを一意に認識できる一時的なusername
パスワード Twilio で認証する際にユーザー名で使用する一時的なパスワードです。
Ttl ユーザー名とパスワードの有効期間(秒単位)です。デフォルト値は 86,400 (24 時間)。
AccountSid このトークンを作成したアカウントの一意な ID です。
IceServers 一時的なクレデンシャルと STUN/TURN サーバー URI を表す配列です。
DateCreated このリソースが生成された日付です。 RFC 2822 フォーマットを使用します。
DateUpdated このリソースが最後に更新された日付です。 RFC 2822 フォーマットを使用します。

HTTP GET

サポートしません。

HTTP POST

Tokens リストリソースに POST することによって、新しいトークンリソースを作成できます。トークンの目的は、短期間有効なクレデンシャルを提供することなので、ユーザー名とパスワードは常に自動生成され、長期間保管されることはありません。

オプションパラメーター

以下のパラメーターを POST します。

パラメーター 説明
Ttl 生成されたクレデンシャルの有効期間(秒単位)です。デフォルト値は 86,400 (24 時間)。
サンプル
トークン・リソースを作成する
  • C#
  • curl
  • Java
  • Node.js
  • PHP
  • Python
  • Ruby
SDKバージョン:
  • 4.x
  • 5.x
レスポンス形式:
  • JSON
  • xml
SDKバージョン:
  • 6.x
  • 7.x
SDKバージョン:
  • 2.x
  • 3.x
SDKバージョン:
  • 4.x
  • 5.x
SDKバージョン:
  • 5.x
  • 6.x
SDKバージョン:
  • 4.x
  • 5.x
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var token = TokenResource.Create();

        Console.WriteLine(token.Username);
    }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$token = $client->tokens->create();

echo $token->username;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

token = client.tokens.create()
print(token.username)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new(account_sid, auth_token)

token = @client.tokens.create
puts token.username
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens.json \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.TokenFactory;
import com.twilio.sdk.resource.instance.Token;
import java.util.ArrayList;
import org.apache.http.NameValuePair;

public class Example {

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    TokenFactory tokenFactory = client.getAccount().getTokenFactory();
    Token token = tokenFactory.create(new ArrayList<NameValuePair>());
    System.out.println(token.getUsername());
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"

client = Client(account_sid, auth_token)

token = client.tokens.create()
print(token.username)
// Download the Node helper library from twilio.com/docs/node/install
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.tokens
  .create()
  .then((token) => process.stdout.write(token.username));
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var token = twilio.CreateToken();
    
    Console.WriteLine(token.Username);
  }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$authToken = "your_auth_token";
$client = new Services_Twilio($sid, $authToken);

$token = $client->account->tokens->create();
echo $token->username;
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

token = @client.account.tokens.create
puts token.username
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Token;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Token token = Token.creator().create();

    System.out.println(token.getUsername());
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.tokens.create({}, function(err, token) {
    process.stdout.write(token.username);
});
出力を表示
  • JSON
  • XML
{
    "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "date_created": "Mon, 17 Nov 2014 23:55:19 +0000",
    "date_updated": "Mon, 17 Nov 2014 23:55:19 +0000",
    "ice_servers": [
        {
            "url": "stun:global.stun.twilio.com:3478?transport=udp"
        },
        {
            "credential": "M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=",
            "url": "turn:global.turn.twilio.com:3478?transport=udp",
            "username": "b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f"
        }
    ],
    "password": "M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=",
    "registrars": null,
    "ttl": "86400",
    "username": "b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f"
}
<?xml version="1.0" encoding="UTF-8"?>
<TwilioResponse>
  <Token>
    <Username>b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f</Username>
    <Password>M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=</Password>
    <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
    <Ttl>86400</Ttl>
    <IceServers>
      <IceServer>
        <Url>stun:global.stun.twilio.com:3478?transport=udp</Url>
      </IceServer>
      <IceServer>
        <Url>turn:global.turn.twilio.com:3478?transport=udp</Url>
        <Username>b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f</Username>
        <Credential>M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=</Credential>
      </IceServer>
    </IceServers>
    <Registrars/>
    <DateCreated>Mon, 17 Nov 2014 23:42:45 +0000</DateCreated>
    <DateUpdated>Mon, 17 Nov 2014 23:42:45 +0000</DateUpdated>
  </Token>
</TwilioResponse>
トークン・リソースを作成する
期限が1時間のサービストークンを作成する
  • C#
  • curl
  • Java
  • Node.js
  • PHP
  • Python
  • Ruby
SDKバージョン:
  • 4.x
  • 5.x
レスポンス形式:
  • JSON
  • xml
SDKバージョン:
  • 6.x
  • 7.x
SDKバージョン:
  • 2.x
  • 3.x
SDKバージョン:
  • 4.x
  • 5.x
SDKバージョン:
  • 5.x
  • 6.x
SDKバージョン:
  • 4.x
  • 5.x
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var token = TokenResource.Create(ttl: 3600);

        Console.WriteLine(token.Username);
    }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$token = $client->tokens->create(
    array("ttl" => 3600)
);

echo $token->username;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

token = client.tokens.create(ttl=3600)
print(token.username)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new(account_sid, auth_token)

token = @client.account.tokens.create(:ttl => 3600)
puts token.username
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens.json \
    -d "Ttl=3600" \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens \
    -d "Ttl=3600" \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.TokenFactory;
import com.twilio.sdk.resource.instance.Token;
import com.twilio.sdk.resource.list.TokenList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

	List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Ttl", "3600"));

    TokenFactory tokenFactory = client.getAccount().getTokenFactory();
    Token token = tokenFactory.create(params);
    System.out.println(token.getUsername());
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"

client = Client(account_sid, auth_token)

token = client.tokens.create(ttl=3600)
print(token.username)
// Download the Node helper library from twilio.com/docs/node/install
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.tokens
	.create({'ttl': 3600})
	.then((token) => process.stdout.write(token.username));
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;

class Example
{
  static void Main(string[] args)
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var token = twilio.CreateToken(3600);

    Console.WriteLine(token.Username);
  }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$authToken = "your_auth_token";
$client = new Services_Twilio($sid, $authToken);

$token = $client->account->tokens->create(3600);
echo $token->username;
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

token = @client.account.tokens.create(:ttl => 3600)
puts token.username
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Token;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Token token = Token.creator().setTtl(3600).create();

    System.out.println(token.getUsername());
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.tokens.create({
	"ttl": 3600
}, function(err, token) {
    process.stdout.write(token.username);
});
出力を表示
  • JSON
  • XML
{
    "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "date_created": "Mon, 17 Nov 2014 23:55:19 +0000",
    "date_updated": "Mon, 17 Nov 2014 23:55:19 +0000",
    "ice_servers": [
        {
            "url": "stun:global.stun.twilio.com:3478?transport=udp"
        },
        {
            "credential": "LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=",
            "url": "turn:global.turn.twilio.com:3478?transport=udp",
            "username": "40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4"
        }
    ],
    "password": "LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=",
    "registrars": null,
    "ttl": "3600",
    "username": "40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4"
}
<?xml version="1.0" encoding="UTF-8"?>
<TwilioResponse>
  <Token>
    <Username>40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4</Username>
    <Password>LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=</Password>
    <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
    <Ttl>3600</Ttl>
    <IceServers>
      <IceServer>
        <Url>stun:global.stun.twilio.com:3478?transport=udp</Url>
      </IceServer>
      <IceServer>
        <Url>turn:global.turn.twilio.com:3478?transport=udp</Url>
        <Username>40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4</Username>
        <Credential>LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=</Credential>
      </IceServer>
    </IceServers>
    <Registrars/>
    <DateCreated>Mon, 17 Nov 2014 23:42:45 +0000</DateCreated>
    <DateUpdated>Mon, 17 Nov 2014 23:42:45 +0000</DateUpdated>
  </Token>
</TwilioResponse>
期限が1時間のサービストークンを作成する

HTTP PUT

サポートしません。

HTTP DELETE

サポートしません。

1 / 1
Loading Code Samples...
SDKバージョン:
  • 4.x
  • 5.x
レスポンス形式:
  • JSON
  • xml
SDKバージョン:
  • 6.x
  • 7.x
SDKバージョン:
  • 2.x
  • 3.x
SDKバージョン:
  • 4.x
  • 5.x
SDKバージョン:
  • 5.x
  • 6.x
SDKバージョン:
  • 4.x
  • 5.x
形式:
  • JSON
  • XML
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var token = TokenResource.Create();

        Console.WriteLine(token.Username);
    }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$token = $client->tokens->create();

echo $token->username;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

token = client.tokens.create()
print(token.username)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new(account_sid, auth_token)

token = @client.tokens.create
puts token.username
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens.json \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.TokenFactory;
import com.twilio.sdk.resource.instance.Token;
import java.util.ArrayList;
import org.apache.http.NameValuePair;

public class Example {

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    TokenFactory tokenFactory = client.getAccount().getTokenFactory();
    Token token = tokenFactory.create(new ArrayList<NameValuePair>());
    System.out.println(token.getUsername());
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"

client = Client(account_sid, auth_token)

token = client.tokens.create()
print(token.username)
// Download the Node helper library from twilio.com/docs/node/install
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.tokens
  .create()
  .then((token) => process.stdout.write(token.username));
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var token = twilio.CreateToken();
    
    Console.WriteLine(token.Username);
  }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$authToken = "your_auth_token";
$client = new Services_Twilio($sid, $authToken);

$token = $client->account->tokens->create();
echo $token->username;
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

token = @client.account.tokens.create
puts token.username
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Token;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Token token = Token.creator().create();

    System.out.println(token.getUsername());
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.tokens.create({}, function(err, token) {
    process.stdout.write(token.username);
});
{
    "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "date_created": "Mon, 17 Nov 2014 23:55:19 +0000",
    "date_updated": "Mon, 17 Nov 2014 23:55:19 +0000",
    "ice_servers": [
        {
            "url": "stun:global.stun.twilio.com:3478?transport=udp"
        },
        {
            "credential": "M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=",
            "url": "turn:global.turn.twilio.com:3478?transport=udp",
            "username": "b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f"
        }
    ],
    "password": "M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=",
    "registrars": null,
    "ttl": "86400",
    "username": "b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f"
}
<?xml version="1.0" encoding="UTF-8"?>
<TwilioResponse>
  <Token>
    <Username>b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f</Username>
    <Password>M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=</Password>
    <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
    <Ttl>86400</Ttl>
    <IceServers>
      <IceServer>
        <Url>stun:global.stun.twilio.com:3478?transport=udp</Url>
      </IceServer>
      <IceServer>
        <Url>turn:global.turn.twilio.com:3478?transport=udp</Url>
        <Username>b759d275ddc641cd379f329882abe3c0618c8afdfc5e24be1b4d59482244240f</Username>
        <Credential>M87Dd74GbNfyrAydvEKiDR43go52fo6ldoJBHB6gim0=</Credential>
      </IceServer>
    </IceServers>
    <Registrars/>
    <DateCreated>Mon, 17 Nov 2014 23:42:45 +0000</DateCreated>
    <DateUpdated>Mon, 17 Nov 2014 23:42:45 +0000</DateUpdated>
  </Token>
</TwilioResponse>
SDKバージョン:
  • 4.x
  • 5.x
レスポンス形式:
  • JSON
  • xml
SDKバージョン:
  • 6.x
  • 7.x
SDKバージョン:
  • 2.x
  • 3.x
SDKバージョン:
  • 4.x
  • 5.x
SDKバージョン:
  • 5.x
  • 6.x
SDKバージョン:
  • 4.x
  • 5.x
形式:
  • JSON
  • XML
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var token = TokenResource.Create(ttl: 3600);

        Console.WriteLine(token.Username);
    }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$token = $client->tokens->create(
    array("ttl" => 3600)
);

echo $token->username;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

token = client.tokens.create(ttl=3600)
print(token.username)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new(account_sid, auth_token)

token = @client.account.tokens.create(:ttl => 3600)
puts token.username
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens.json \
    -d "Ttl=3600" \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Tokens \
    -d "Ttl=3600" \
    -u "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token"
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.TokenFactory;
import com.twilio.sdk.resource.instance.Token;
import com.twilio.sdk.resource.list.TokenList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

	List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Ttl", "3600"));

    TokenFactory tokenFactory = client.getAccount().getTokenFactory();
    Token token = tokenFactory.create(params);
    System.out.println(token.getUsername());
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"

client = Client(account_sid, auth_token)

token = client.tokens.create(ttl=3600)
print(token.username)
// Download the Node helper library from twilio.com/docs/node/install
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.tokens
	.create({'ttl': 3600})
	.then((token) => process.stdout.write(token.username));
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;

class Example
{
  static void Main(string[] args)
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var token = twilio.CreateToken(3600);

    Console.WriteLine(token.Username);
  }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$authToken = "your_auth_token";
$client = new Services_Twilio($sid, $authToken);

$token = $client->account->tokens->create(3600);
echo $token->username;
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

token = @client.account.tokens.create(:ttl => 3600)
puts token.username
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Token;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Token token = Token.creator().setTtl(3600).create();

    System.out.println(token.getUsername());
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.tokens.create({
	"ttl": 3600
}, function(err, token) {
    process.stdout.write(token.username);
});
{
    "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "date_created": "Mon, 17 Nov 2014 23:55:19 +0000",
    "date_updated": "Mon, 17 Nov 2014 23:55:19 +0000",
    "ice_servers": [
        {
            "url": "stun:global.stun.twilio.com:3478?transport=udp"
        },
        {
            "credential": "LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=",
            "url": "turn:global.turn.twilio.com:3478?transport=udp",
            "username": "40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4"
        }
    ],
    "password": "LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=",
    "registrars": null,
    "ttl": "3600",
    "username": "40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4"
}
<?xml version="1.0" encoding="UTF-8"?>
<TwilioResponse>
  <Token>
    <Username>40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4</Username>
    <Password>LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=</Password>
    <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
    <Ttl>3600</Ttl>
    <IceServers>
      <IceServer>
        <Url>stun:global.stun.twilio.com:3478?transport=udp</Url>
      </IceServer>
      <IceServer>
        <Url>turn:global.turn.twilio.com:3478?transport=udp</Url>
        <Username>40a90ad073c0ac74820142e5ba7fe4e6a1e83db2c48bff30a7ea6c47862c8bc4</Username>
        <Credential>LyCKdB0y9jfJqjppGHRtBqfPXtUFTwtZHw4Qpf9LnH4=</Credential>
      </IceServer>
    </IceServers>
    <Registrars/>
    <DateCreated>Mon, 17 Nov 2014 23:42:45 +0000</DateCreated>
    <DateUpdated>Mon, 17 Nov 2014 23:42:45 +0000</DateUpdated>
  </Token>
</TwilioResponse>