Reputation: 415
const Twilio = require('twilio');
const request = require('request');
const apiKeySid = 'SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const apiKeySecret = 'your_api_key_secret';
const accountSid = 'ACb46a83261c60f3a45ce47eccac8a913d';
const client = new Twilio(apiKeySid, apiKeySecret, { accountSid:
accountSid });
const roomSid = 'RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const recordingSid = 'RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const uri = 'https://video.twilio.com/v1/' +
`Rooms/${roomSid}/` +
`Recordings/${recordingSid}` +
'/Media';
const response = client.request({ method: "POST", uri: uri });
const mediaLocation = JSON.parse(response.body).location;
request.get(mediaLocation, (err, res, media) => {
console.log(media);
});
I tried to retrieve recorded media but this is not working and getting undefined when I am printing response.body.
Upvotes: 1
Views: 311
Reputation: 415
@philnash I tried this above code block but getting "mediaLocation" as undefined.
Changed JSON.parse(response.body).location to JSON.parse(response.body).redirect_to and it's working.
client.request({ method: "GET", uri: uri }).then((response) => {
const mediaLocation = JSON.parse(response.body).redirect_to;
request.get(mediaLocation, (err, res, media) => {
console.log(media);
});
});
response:
{ statusCode: 302,
body: '{"redirect_to":
"https://xxxxxxxxxxxxx.s3.amazonaws.com/xxxxxxxxxxxxxxxxxxxxx…….”}’ }
Upvotes: 0
Reputation: 73057
Twilio developer evangelist here.
Apologies, that is a mistake in our documentation. Calling client.request
is an asynchronous call and returns a Promise
.
Try this instead:
client.request({ method: "GET", uri: uri }).then(response => {
const mediaLocation = JSON.parse(response.body).location;
request.get(mediaLocation, (err, res, media) => {
console.log(media);
});
});
I've started a pull request to get this back into the documentation here too.
Upvotes: 1