title: Twilio Video Calling API implementation
body: <p>I am implementing Video calling api for my project, when i create Access Token from <a href="https://www.twilio.com/user/account/video/dev-tools/testing-tools" rel="nofollow">https://www.twilio.com/user/account/video/dev-tools/testing-tools</a> by <strong>"Generate Access Token"</strong> option it will give me new generated token and when i use it as below</p>
  
  <pre><code>var accessToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJTSzk3ZDI2NGIyOTU1YjM2OWMyOGU4MjA4M2E5MjlmMmE0LTE0NjYwODE1NzQiLCJpc3MiOiJTSzk3ZDI2NGIyOTU1YjM2OWMyOGU4MjA4M2E5MjlmMmE0Iiwic3ViIjoiQUM5ZWE5YjY3ZmM3ZjBjMzE2NTBjNGRmNzkyYzhjYjI2NiIsImV4cCI6MTQ2NjA4NTE3NCwiZ3JhbnRzIjp7ImlkZW50aXR5IjoiQUM5ZWE5YjY3ZmM3ZjBjMzE2NTBjNGRmNzkyYzhjYjI2NiIsInJ0YyI6eyJjb25maWd1cmF0aW9uX3Byb2ZpbGVfc2lkIjoiVlMwNmYzZDdiNTczNGVlYTJhZDdjMWEzYzY4YmMzNjhjNSJ9fX0.976iQ2bMB_tAORxjGkgZFJ-UYGfTidTwfvV0fzySMP0";
  
  var accessManager = new Twilio.AccessManager(accessToken); 
  </code></pre>
  
  <p>it will works great for me.</p>
  
  <p>Now when i use 2nd option <strong>"Generate an Access Token via Helper Library with PHP"</strong> and try to generate token with </p>
  
  <pre><code>// 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-&gt;setConfigurationProfileSid($configurationProfileSid);
  $token-&gt;addGrant($grant);
  
  echo json_encode(array(
      'identity' =&gt; $identity,
      'token' =&gt; $token-&gt;toJWT(),
  ));
  </code></pre>
  
  <p>it will also generate token for me but when i use generated token as</p>
  
  <p><strong>Response Token:</strong>  </p>
  
  <pre><code>{"identity":"GoldenZeldaGunsight","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0
  .eyJqdGkiOiJTSzk3ZDI2NGIyOTU1YjM2OWMyOGU4MjA4M2E5MjlmMmE0LTE0NjYxMzc4MTkiLCJpc3MiOiJTSzk3ZDI2NGIyOTU
  1YjM2OWMyOGU4MjA4M2E5MjlmMmE0Iiwic3ViIjoiQUM5ZWE5YjY3ZmM3ZjBjMzE2NTBjNGRmNzkyYzhjYjI2NiIsIm5iZiI6MTQ
  2NjEzNzgxOSwiZXhwIjoxNDY2MTQxNDE5LCJncmFudHMiOnsiaWRlbnRpdHkiOiJHb2xkZW5aZWxkYUd1bnNpZ2h0IiwicnRjIjp7ImNvbmZpZ3VyYXRpb25fcHJvZmlsZV9zaWQiOiJWUzA2ZjNkN2I1NzM0ZWVhMmFkN2MxYTNjNjhiYzM2OGM1In19fQ
  .vkOxI1tMIWNQVm1AUL1ySTZY5ZyjYDTdvWCKnVIkLmk"}
  </code></pre>
  
  <p>I use this response token in </p>
  
  <pre><code>var accessManager = new Twilio.AccessManager(data.token);
  </code></pre>
  
  <p>it will not works for me. it will give me error like </p>
  
  <blockquote>
    <p>"Could not connect to Twilio: undefined..."</p>
  </blockquote>
  
  <p><strong>Response :</strong> </p>
  
  <pre><code>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: &lt;sip:AC9ea9b67fc7f0c31650c4df792c8cb266@AC9ea9b67fc7f0c31650c4df792c8cb266.endpoint.twilio.com&gt;;tag=l3bsmhddlr
  To: &lt;sip:AC9ea9b67fc7f0c31650c4df792c8cb266@AC9ea9b67fc7f0c31650c4df792c8cb266.endpoint.twilio.com&gt;;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
  </code></pre>
  
  <p>Also i have tested both token on <a href="https://jwt.io" rel="nofollow">https://jwt.io</a> , its working perfect for me. </p>
  
  <p>Can anyone please help me in this matter where i am wrong with code , if you want then i can pass other credentials details as well  ?</p>
  
  <p>Thanks in advance.</p>
  
  <blockquote>
    <p><strong>Solved</strong></p>
  </blockquote>
  
  <p>Guys, I'v got solution of this issue with the help of Support.</p>
  
  <p><strong>Solution</strong></p>
  
  <p>In my old version of <code>/Services/Twilio/AccessToken.php</code> , I have an attribute "nbf": 1466743969<code>(not-before time), which means it is not valid until</code>04:52:49 UTC<code>. However according to the timestamp in the log file it was</code>04:50:27 UTC (10:20:27 IST)`. If the system clock of the server generating the access token is a couple minutes fast it will result in an invalid not-before time.</p>
  
  <p>Later versions of the twilio-php library omitted the <code>"nbf"</code> attribute by default, because of this clock skew issue. If you get the latest version of AccessToken.php here:</p>
  
  <pre><code>https://github.com/twilio/twilio-php/blob/master/Services/Twilio/AccessToken.php
  </code></pre>
  
  <p>it will generate access tokens without <code>"nbf"</code>.</p>
  
  <p>An alternate fix would be to make sure the server time is accurate, but you would need administrator access to adjust it.</p>