Discussions

Ask a Question
Back to All

Start stream error 500

This is my php code for starting stream but returned 500 error.

<?php
    require_once('vendor/autoload.php');

    $client = new \GuzzleHttp\Client();

    $id = $_POST['id'];
    $session_id = $_POST['session_id'];
    $sdp = $_POST['sdp'];
    $type = $_POST['type'];

    $url = 'https://api.d-id.com/talks/streams/' . $id . '/sdp';
    $body = '{"answer":{"type":"answer","sdp":"' . $sdp . '"},"session_id":"' . $session_id . '"}';

    $response = $client->request('POST', $url, [
        'body' => $body,
        'headers' => [
            'accept' => 'application/json',
            'authorization' => 'Basic [MY API KEY]',
            'content-type' => 'application/json',
        ],
    ]);

    echo $response->getBody();

?>
    $.ajax({
        url: 'stream_new.php',
        'method': 'post'
    }).done(function(res) {
        res = JSON.parse(res);

        var id= res.id;
        var session_id = res.session_id;
        var sdp = res.offer.sdp;
        var type = res.offer.type;

        $.ajax({
            url: 'stream_start.php',
            'method': 'post',
            data: {'id':id, 'session_id':session_id, 'sdp':sdp, 'type':type}
        }).done(function(res2) {
            res2 = JSON.parse(res2);
            console.log('session_start', res2);
        });
    });

id, session_id, sdp it's returned value from create stream call. Can i fix it?