This repository was archived by the owner on Aug 15, 2024. It is now read-only.
File tree 5 files changed +13
-17
lines changed
rest/access-tokens/live-example
5 files changed +13
-17
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ const twilioAccountSid = process.env.TWILIO_ACCOUNT_SID;
7
7
const twilioApiKey = process . env . TWILIO_API_KEY ;
8
8
const twilioApiSecret = process . env . TWILIO_API_SECRET ;
9
9
10
+ // Initialize a Twilio client
11
+ const client = require ( 'twilio' ) ( twilioApiKey , twilioApiSecret , {
12
+ accountSid : twilioAccountSid } ) ;
13
+
10
14
// Create an access token which you will sign and return to the client,
11
15
// containing the grant you will create in the next steps
12
16
const token = new AccessToken (
@@ -17,8 +21,6 @@ const token = new AccessToken(
17
21
18
22
// Create a PlaybackGrant resource for a specific PlayerStreamer
19
23
// via the REST API
20
- const client = require ( 'twilio' ) ( twilioApiKey , twilioApiSecret , {
21
- accountSid : twilioAccountSid } ) ;
22
24
client . media . playerStreamer ( 'VJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' )
23
25
. playbackGrant ( )
24
26
. create ( { ttl : 60 } )
Original file line number Diff line number Diff line change @@ -22,23 +22,20 @@ static void Main(string[] args)
22
22
TwilioClient . Init ( twilioApiKey , twilioApiSecret , twilioAccountSid ) ;
23
23
var playbackGrant = PlaybackGrantResource . Create (
24
24
ttl : 60 ,
25
- pathSid : "VJ3f3dc19da15af020bb395f0487f5221d "
25
+ pathSid : "VJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "
26
26
) ;
27
27
28
28
// Serialize the returned grant into <Dictionary<string, object>>
29
29
var json = JsonConvert . SerializeObject ( playbackGrant . Grant ) ;
30
30
var grantDictionary = JsonConvert . DeserializeObject < Dictionary < string , object > > ( json ) ;
31
31
32
32
// Wrap the grant you received from the API
33
- // in a PlaybackGrant object and then attach that wrapped
34
- // grant to your Access Token
35
- var wrappedPlaybackGrant = new PlaybackGrant ( ) ;
36
- Console . WriteLine ( playbackGrant ) ;
37
- wrappedPlaybackGrant . Grant = grantDictionary ;
33
+ // in a PlaybackGrant object
34
+ var wrappedPlaybackGrant = new PlaybackGrant { Grant = grantDictionary } ;
38
35
39
36
var grants = new HashSet < IGrant > { wrappedPlaybackGrant } ;
40
37
41
- // Create an Access Token generator and attach the grants
38
+ // Create an Access Token generator and attach the PlaybackGrant
42
39
var token = new Token (
43
40
twilioAccountSid ,
44
41
twilioApiKey ,
Original file line number Diff line number Diff line change 28
28
->create (["ttl " => 60 ]);
29
29
30
30
// Wrap the grant you received from the API
31
- // in a PlaybackGrant object and then attach that wrapped
32
- // grant to your Access Token
31
+ // in a PlaybackGrant object
33
32
$ wrappedPlaybackGrant = new PlaybackGrant ();
34
33
$ wrappedPlaybackGrant ->setGrant ($ playbackGrant ->grant );
35
34
36
- // Add grant to token
35
+ // Attach the PlaybackGrant to the Access Token
37
36
$ token ->addGrant ($ wrappedPlaybackGrant );
38
37
39
38
// render token to string
Original file line number Diff line number Diff line change 15
15
. create ( ttl : 60 )
16
16
17
17
# Wrap the grant you received from the API
18
- # in a PlaybackGrant object and then attach that wrapped
19
- # grant to your Access Token
18
+ # in a PlaybackGrant object
20
19
wrapped_playback_grant = Twilio ::JWT ::AccessToken ::PlaybackGrant . new
21
20
wrapped_playback_grant . grant = playback_grant . grant
22
21
Original file line number Diff line number Diff line change @@ -21,11 +21,10 @@ public static void main(String[] args) {
21
21
.create ();
22
22
23
23
// Wrap the grant you received from the API
24
- // in a PlaybackGrant object and then attach that wrapped
25
- // grant to your Access Token
24
+ // in a PlaybackGrant object
26
25
PlaybackGrant wrappedPlaybackGrant = new PlaybackGrant ().setGrant (playbackGrant .getGrant ());
27
26
28
- // Create access token
27
+ // Create an Access Token and add the PlaybackGrant to it
29
28
AccessToken token = new AccessToken .Builder (
30
29
twilioAccountSid ,
31
30
twilioApiKey ,
You can’t perform that action at this time.
0 commit comments