Reputation: 344
I am working with video feature with twilio. I have code like this,
File index.php
require_once('vendor/autoload.php');
use Twilio\Jwt\AccessToken;
use Twilio\Jwt\Grants\VideoGrant;
// Substitute your Twilio AccountSid and ApiKey details
$accountSid = 'ACxxxxxxxxxxxxxxxxxx';
$apiKeySid = 'SKxxxxxxxxxxxxxxxxxxx';
$apiKeySecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
$identity = 'chatroom';
// Create an Access Token
$token = new AccessToken(
$accountSid,
$apiKeySid,
$apiKeySecret,
3600,
$identity
);
// Grant access to Video
$grant1 = new VideoGrant();
$grant1->setRoom('php');
$token->addGrant($grant1);
// Serialize the token as a JWT
echo $token->toJWT();
With this, I am getting access token and I am using this with below code:
local.js
var accessToken = 'token';
var accessManager = Twilio.AccessManager(accessToken);
//console.log(accessManager);
var client = Twilio.Conversations.Client(accessManager);
// Begin listening for invites to Twilio Video conversations.
client.listen().then(function() {
client.on('invite', function(invite) {
invite.accept().then(onInviteAccepted);
});
});
But I am getting error like this
SIP/2.0 403 Forbidden
CSeq: 81 REGISTER
Call-ID: pgilp7ph926lumbhvn9
From: <sip:[email protected]>;tag=77troiv7s5
To: <sip:[email protected]>;tag=12029129_f28f532c_80fa4-ec12-4818-8a18-f4a4fe766
Via: SIP/2.0/WSS 127.0.0.1:49162;branch=z9hG4bK877168;rport=49162
Server: Twilio
X-Twilio-Error: 20101 Invalid Access Token
Content-Length: 0
Upvotes: 1
Views: 1707
Reputation: 183
firstly You need to make sure that your API key, Secret key and account SID are correct. Secondly , The error suggests that your key generated using above three data points is not correct/accepted by Twilio . To check if the token is structurally correct visit here.
Upvotes: 1