Can I setup a PHP Twilio application server and grant push capabilities
<p>I currently use a Python Twilio application server and grant push capabilities to my tokens with the following lines of code:</p>

<pre><code>@app.route('/accessToken')
def token():
  account_sid = os.environ.get("ACCOUNT_SID", ACCOUNT_SID)
  api_key = os.environ.get("API_KEY", API_KEY)
  api_key_secret = os.environ.get("API_KEY_SECRET", API_KEY_SECRET)
  push_credential_sid = os.environ.get("PUSH_CREDENTIAL_SID", PUSH_CREDENTIAL_SID)
  app_sid = os.environ.get("APP_SID", APP_SID)

  grant = VoiceGrant(
    push_credential_sid=push_credential_sid,
    outgoing_application_sid=app_sid
  )

  token = AccessToken(account_sid, api_key, api_key_secret, IDENTITY)
  token.add_grant(grant)

  return str(token)
</code></pre>

<p>Is there a way for me to do that with PHP? I have loaded Twilio dependencies with composer and can get a token just fine. I just don't know how to add push capabilities to the token. These lines currently generate tokens (but not with push capabilities):</p>

<pre><code>&lt;?php
include('./vendor/autoload.php');
include('./config.php');
include('./randos.php');

use Twilio\Jwt\ClientToken;
use Twilio\Jwt\Grants;

// choose a random username for the connecting user
$identity = $_GET['identity'];

$capability = new ClientToken($TWILIO_ACCOUNT_SID, $TWILIO_AUTH_TOKEN);
$capability-&gt;allowClientOutgoing($TWILIO_TWIML_APP_SID);
$capability-&gt;allowClientIncoming($identity);
$token = $capability-&gt;generateToken();

echo $token;
?&gt;
</code></pre>

<p>Thanks to a tip from Zack with Twilio, I finally got this working!</p>

<pre><code>include('./vendor/autoload.php');
include('./config.php');
include('./randos.php');

use Twilio\Jwt\AccessToken;
use Twilio\Jwt\Grants;
use Twilio\Jwt\Grants\VoiceGrant;
use Twilio\Rest\Client;

// choose a random username for the connecting user
$identity = randomUsername();


$token = new AccessToken($TWILIO_ACCOUNT_SID, $API_KEY, $API_KEY_SECRET, 3600, $identity);

$grant = new VoiceGrant();
$grant-&gt;setPushCredentialSid($PUSH_CREDENTIAL_SID);
$grant-&gt;setOutgoingApplicationSid($TWILIO_TWIML_APP_SID);
$token-&gt;addGrant($grant);

echo $token;
</code></pre>

php python twilio