twilio-video-app-react icon indicating copy to clipboard operation
twilio-video-app-react copied to clipboard

Custom Token API

Open DeepakDums1998 opened this issue 3 years ago • 2 comments

Question I have created a custom API in PHP for fetching tokens everything is going well but there is an issue in the conversation API

I am getting the following error There was a problem getting the Conversation associated with this room. Error: There was a problem getting the Conversation associated with this room.

here is my API CODE which I have created

`
$requestdata = json_decode($request->getContent(), true);

    // Substitute your Twilio Account SID and API Key details
    $accountSid = env('TWILIO_ACCOUNT_SID');
    $apiKeySid = env('TWILIO_API_KEY_SID');
    $authtoken = '5fbd7ad7f6c7795fd3359c6d5550a0c5';
    $apiKeySecret = env('TWILIO_API_KEY_SECRET');
    $conversation_sid = env('TWILIO_CONVERSATIONS_SERVICE_SID');
    $identity = $requestdata['user_identity'];
    // Create an Access Token
    $token = new AccessToken(
        $accountSid,
        $apiKeySid,
        $apiKeySecret,
        3600,
        $identity
    );

    //Grant access to Video
    $grant = new VideoGrant();
    $grant->setRoom($requestdata['room_name']);
    $token->addGrant($grant);

    // // Create Chat grant
    $chatGrant = new ChatGrant();
    $chatGrant->setServiceSid($conversation_sid);
    $token->addGrant($chatGrant);
    $twilio = new Client(
        $accountSid,
        $authtoken
    );
    $conversation_service = $twilio->conversations->v1->services($conversation_sid)->conversations
        ->create(
            [
                "friendlyName" => $requestdata['room_name'],
                "uniqueName" => $requestdata['room_name']
            ]
        );
    // Serialize the token as a JWT
    // echo $token->toJWT();
    return response()->json([
        'token' => $token->toJWT(),
        'room_type' => 'group',
        'conversation_id' => $conversation_service->sid
    ]);`

Additional context https://prnt.sc/2arWzh4uIvwJ

DeepakDums1998 avatar Sep 24 '22 11:09 DeepakDums1998

Hi @DeepakDums1998 ,

Thanks for writing in with your question. The error raised usually has a code associated with it. Can you share it with me? Also, is there a way I can access a deployed version of your app? That will help me with debugging.

manjeshbhargav avatar Sep 29 '22 17:09 manjeshbhargav

Hi, We have the same issue. We are using java to create the custom token using the Twilio Helper Library. I do not see an error code associated with the error. Below are screen shots of the errors and the console.

Screenshot 2023-09-19 at 10 12 01 AM Screenshot 2023-09-19 at 10 11 19 AM

Here is how we are creating the token. `
import com.twilio.Twilio; import com.twilio.jwt.accesstoken.AccessToken; import com.twilio.jwt.accesstoken.ChatGrant; import com.twilio.jwt.accesstoken.VideoGrant;

VideoGrant roomGrant = new VideoGrant() .setRoom(room); ChatGrant chatGrant = new ChatGrant(); chatGrant.setServiceSid(serviceSid);

    token = new AccessToken.Builder(
            ACCOUNT_SID,
            twilioApiKey,
            twilioApiSecret
    )
            .identity(attendeeName)
            .grant(roomGrant)
            .grant(chatGrant)
            .build();

`

Any hints on how to work around this error?

runnermann avatar Sep 19 '23 14:09 runnermann