我正在为我的项目实现视频通话 api,当我通过“生成访问令牌”选项从https://www.twilio.com/user/account/video/dev-tools/testing-tools创建访问令牌时,它会给我新生成的令牌,当我使用它时如下
var accessToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJTSzk3ZDI2NGIyOTU1YjM2OWMyOGU4MjA4M2E5MjlmMmE0LTE0NjYwODE1NzQiLCJpc3MiOiJTSzk3ZDI2NGIyOTU1YjM2OWMyOGU4MjA4M2E5MjlmMmE0Iiwic3ViIjoiQUM5ZWE5YjY3ZmM3ZjBjMzE2NTBjNGRmNzkyYzhjYjI2NiIsImV4cCI6MTQ2NjA4NTE3NCwiZ3JhbnRzIjp7ImlkZW50aXR5IjoiQUM5ZWE5YjY3ZmM3ZjBjMzE2NTBjNGRmNzkyYzhjYjI2NiIsInJ0YyI6eyJjb25maWd1cmF0aW9uX3Byb2ZpbGVfc2lkIjoiVlMwNmYzZDdiNTczNGVlYTJhZDdjMWEzYzY4YmMzNjhjNSJ9fX0.976iQ2bMB_tAORxjGkgZFJ-UYGfTidTwfvV0fzySMP0";
var accessManager = new Twilio.AccessManager(accessToken);
它对我很有用。
现在,当我使用第二个选项“使用 PHP 通过 Helper Library 生成访问令牌”并尝试使用
// Create an Access Token
$token = new Services_Twilio_AccessToken(
$accountSid,
$apiKeySid,
$apiKeySecret,
$ttl=3600,
$identity=$identity
);
// Grant access to Conversations
$grant = new Services_Twilio_Auth_ConversationsGrant();
$grant->setConfigurationProfileSid($configurationProfileSid);
$token->addGrant($grant);
echo json_encode(array(
'identity' => $identity,
'token' => $token->toJWT(),
));
它也会为我生成令牌但是当我使用生成的令牌作为
响应令牌:
{"identity":"GoldenZeldaGunsight","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0
.eyJqdGkiOiJTSzk3ZDI2NGIyOTU1YjM2OWMyOGU4MjA4M2E5MjlmMmE0LTE0NjYxMzc4MTkiLCJpc3MiOiJTSzk3ZDI2NGIyOTU
1YjM2OWMyOGU4MjA4M2E5MjlmMmE0Iiwic3ViIjoiQUM5ZWE5YjY3ZmM3ZjBjMzE2NTBjNGRmNzkyYzhjYjI2NiIsIm5iZiI6MTQ
2NjEzNzgxOSwiZXhwIjoxNDY2MTQxNDE5LCJncmFudHMiOnsiaWRlbnRpdHkiOiJHb2xkZW5aZWxkYUd1bnNpZ2h0IiwicnRjIjp7ImNvbmZpZ3VyYXRpb25fcHJvZmlsZV9zaWQiOiJWUzA2ZjNkN2I1NzM0ZWVhMmFkN2MxYTNjNjhiYzM2OGM1In19fQ
.vkOxI1tMIWNQVm1AUL1ySTZY5ZyjYDTdvWCKnVIkLmk"}
我在
var accessManager = new Twilio.AccessManager(data.token);
它对我不起作用。它会给我这样的错误
“无法连接到 Twilio:未定义...”
回复 :
Thu Jun 23 2016 13:22:58 GMT+0530 (India Standard Time) | sip.transport | received WebSocket text message:
SIP/2.0 403 Forbidden
CSeq: 81 REGISTER
Call-ID: 4704t9hejng0hmhih2ui8m
From: <sip:AC9ea9b67fc7f0c31650c4df792c8cb266@AC9ea9b67fc7f0c31650c4df792c8cb266.endpoint.twilio.com>;tag=l3bsmhddlr
To: <sip:AC9ea9b67fc7f0c31650c4df792c8cb266@AC9ea9b67fc7f0c31650c4df792c8cb266.endpoint.twilio.com>;tag=72132201_50f4772f_8dc5c7c0-ce8e-4a6e-803a-72f6c761338b
Via: SIP/2.0/WSS 127.0.0.1:60911;branch=z9hG4bK2792018;rport=60911
Server: Twilio
X-Twilio-Error: 31201 Authentication failed
Content-Length: 0
我还在https://jwt.io上测试了这两个令牌,它对我来说非常适合。
任何人都可以在我对代码有错误的地方帮助我吗?如果你愿意,我也可以传递其他凭据详细信息吗?
提前致谢。
解决了
伙计们,在支持的帮助下,我已经解决了这个问题。
解决方案
在我的旧版本中/Services/Twilio/AccessToken.php
,我有一个属性“nbf”:1466743969 (not-before time), which means it is not valid until
04:52:49 UTC . However according to the timestamp in the log file it was
04:50:27 UTC (10:20:27 IST)`。如果生成访问令牌的服务器的系统时钟快了几分钟,则会导致无效的 not-before 时间。
由于时钟偏差问题,更高版本的 twilio-php 库"nbf"
默认省略了该属性。如果您在此处获得最新版本的 AccessToken.php:
https://github.com/twilio/twilio-php/blob/master/Services/Twilio/AccessToken.php
它将生成没有"nbf"
.
另一种解决方法是确保服务器时间准确,但您需要管理员访问权限才能对其进行调整。