OpenTok PHP SDK createSession not working

2019-06-09 20:05发布

问题:

I've just installed the latest php sdk of opentok.

I cannot get a session to be created and it's extremely frustrating.

I know the SDK is correctly imported because my first call works. Here is my code.

<?PHP
require("./../classes/opentok.phar");

use OpenTok\OpenTok;
use OpenTok\Session;
use OpenTok\Role; 
use OpenTok\MediaMode;

$API_KEY            = '45972332';
$API_SECRET         = 'HIDDEN_FOR_MY_PROTECTION';

$apiObj             = new OpenTok($API_KEY, $API_SECRET);

var_dump($apiObj); // this returned successful data.

$session            = $apiObj->createSession(array('mediaMode' => 
MediaMode::RELAYED)); // this errors out the script.
?>

This is the error it returns to me.

Fatal error: Uncaught exception 'Guzzle\Http\Exception\ClientErrorResponseException' with message 'Client error response [status code] 403 [reason phrase] Forbidden [url] https://api.opentok.com/session/create' in phar:///var/www/html/API/classes/opentok.phar/vendor/guzzle/guzzle/src/Guzzle/Http/Exception/BadResponseException.php:43
Stack trace:
#0 phar:///var/www/html/API/classes/opentok.phar/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Request.php(145): Guzzle\Http\Exception\BadResponseException::factory(Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Message\Response))
#1 [internal function]: Guzzle\Http\Message\Request::onRequestError(Object(Guzzle\Common\Event), 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher))
#2 phar:///var/www/html/API/classes/opentok.phar/vendor/symfony/event-dispatcher/EventDispatcher.php(184): call_user_func(Array, Object(Guzzle\Common\Event), 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher))
#3 phar:///var/www/html/API/ in phar:///var/www/html/API/classes/opentok.phar/vendor/guzzle/guzzle/src/Guzzle/Http/Exception/BadResponseException.php on line 43

回答1:

I've seen similar issues to this when the clock is out of sync with the OpenTok server. See OpenTok constructor/create_session fails when not running venv



标签: php tokbox