0

I am using a PHP server to generate token. When I initialize the chat client with the token generated, I am getting this error.

POST https://ems.us1.twilio.com/v1/token 401 (Unauthorized)

{"message":"The authorization with Token failed","code":2016,"user_error":false,"params":{"description":"Could not authenticate fpa token"}}

EMS E: Error: The authorization with Token failed

Javascript (v2.1) initilization code:

    Twilio.Chat.Client.create(token).then(client => {
        chatClient = client;
        chatClient.getChannelByUniqueName(channelName)
        .then(function(chosenChannel) {
            myChannel=chosenChannel;

PHP Server code:

    $token = new AccessToken( $accountid, $apikey, $apisecret 3600, 
    $identity);


    $chatGrant = new ChatGrant();
    $chatGrant->setServiceSid($configs[1]);
    $chatGrant->setEndpointId($endpointId);

    $token->addGrant($chatGrant);

    return $token->toJWT(); 

Any help?

arun kumar
  • 703
  • 2
  • 13
  • 33

2 Answers2

0

left colon in $token = new AccessToken( $accountid, $apikey, $apisecret ##HERE## 3600, $identity);

0

You are missing a colon in between the BOLD text below.

$token = new AccessToken( $accountid, $apikey, $apisecret 3600, $identity);

Mayur
  • 4,345
  • 3
  • 26
  • 40