This repository was archived by the owner on Aug 15, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +13
-17
lines changed
rest/access-tokens/live-example Expand file tree Collapse file tree 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;
77const twilioApiKey = process . env . TWILIO_API_KEY ;
88const twilioApiSecret = process . env . TWILIO_API_SECRET ;
99
10+ // Initialize a Twilio client
11+ const client = require ( 'twilio' ) ( twilioApiKey , twilioApiSecret , {
12+ accountSid : twilioAccountSid } ) ;
13+
1014// Create an access token which you will sign and return to the client,
1115// containing the grant you will create in the next steps
1216const token = new AccessToken (
@@ -17,8 +21,6 @@ const token = new AccessToken(
1721
1822// Create a PlaybackGrant resource for a specific PlayerStreamer
1923// via the REST API
20- const client = require ( 'twilio' ) ( twilioApiKey , twilioApiSecret , {
21- accountSid : twilioAccountSid } ) ;
2224client . media . playerStreamer ( 'VJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' )
2325 . playbackGrant ( )
2426 . create ( { ttl : 60 } )
Original file line number Diff line number Diff line change @@ -22,23 +22,20 @@ static void Main(string[] args)
2222 TwilioClient . Init ( twilioApiKey , twilioApiSecret , twilioAccountSid ) ;
2323 var playbackGrant = PlaybackGrantResource . Create (
2424 ttl : 60 ,
25- pathSid : "VJ3f3dc19da15af020bb395f0487f5221d "
25+ pathSid : "VJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "
2626 ) ;
2727
2828 // Serialize the returned grant into <Dictionary<string, object>>
2929 var json = JsonConvert . SerializeObject ( playbackGrant . Grant ) ;
3030 var grantDictionary = JsonConvert . DeserializeObject < Dictionary < string , object > > ( json ) ;
3131
3232 // 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 } ;
3835
3936 var grants = new HashSet < IGrant > { wrappedPlaybackGrant } ;
4037
41- // Create an Access Token generator and attach the grants
38+ // Create an Access Token generator and attach the PlaybackGrant
4239 var token = new Token (
4340 twilioAccountSid ,
4441 twilioApiKey ,
Original file line number Diff line number Diff line change 2828 ->create (["ttl " => 60 ]);
2929
3030// 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
3332$ wrappedPlaybackGrant = new PlaybackGrant ();
3433$ wrappedPlaybackGrant ->setGrant ($ playbackGrant ->grant );
3534
36- // Add grant to token
35+ // Attach the PlaybackGrant to the Access Token
3736$ token ->addGrant ($ wrappedPlaybackGrant );
3837
3938// render token to string
Original file line number Diff line number Diff line change 1515 . create ( ttl : 60 )
1616
1717# 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
2019wrapped_playback_grant = Twilio ::JWT ::AccessToken ::PlaybackGrant . new
2120wrapped_playback_grant . grant = playback_grant . grant
2221
Original file line number Diff line number Diff line change @@ -21,11 +21,10 @@ public static void main(String[] args) {
2121 .create ();
2222
2323 // 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
2625 PlaybackGrant wrappedPlaybackGrant = new PlaybackGrant ().setGrant (playbackGrant .getGrant ());
2726
28- // Create access token
27+ // Create an Access Token and add the PlaybackGrant to it
2928 AccessToken token = new AccessToken .Builder (
3029 twilioAccountSid ,
3130 twilioApiKey ,
You can’t perform that action at this time.
0 commit comments