working with php - api

Official OpenTok Server-Side libraries

working with php - api

Postby intel » Tue Aug 09, 2011 12:58 pm

Code: Select all
Archived Post


Hi everyone.I was working with the php sdk last night and unfortuately could not run the code on thr server.code below:<?php/*!* OpenTok PHP Library* http://www.tokbox.com/** Copyright 2010, TokBox, Inc.**/
            <?php    require_once 'SDK/API_Config.php';    require_once 'SDK/OpenTokSDK.php';    require_once 'SDK/SessionPropertyConstants.php';
    $apiObj = new OpenTokSDK(API_Config::API_KEY, API_Config::API_SECRET);
    $session = $apiObj->create_session($_SERVER["REMOTE_ADDR"];         array(SessionPropertyConstants::MULTIPLEXER_NUMOUTPUTSTREAMS=>2;        SessionPropertyConstants::MULTIPLEXER_SWITCHTYPE=>1;        SessionPropertyConstants::MULTIPLEXER_SWITCHTIMEOUT=>5000));    echo $session->getSessionId();?>?>
<html><head>

<title>chrome</title> <script src="http://static.opentok.com/v0.91/js/TB.min.js"></script><script type="text/javascript" src="/scripts/application.js"></script><script type="text/javascript">
var apiKey = "2248802";var sessionId = '<?php print $sessionId; ?>';var token = '<?php print $apiObj->generate_token($sessionId); ?>';
var session;
                        TB.addEventListener('exception', exceptionHandler);                         session = TB.initSession(sessionId);
                        //Video chat event listeners                         session.addEventListener('sessionConnected', sessionConnectedHandler);                         session.addEventListener('streamCreated', streamCreatedHandler);                     session.addEventListener('streamDestroyed', streamDestroyedHandler);
                        session.connect(apiKey, token);
</script>
</head><body>

</body></html>1. when i run it on my browser this is what i get:create_session($_SERVER["REMOTE_ADDR"]; array(SessionPropertyConstants::MULTIPLEXER_NUMOUTPUTSTREAMS=>2; SessionPropertyConstants::MULTIPLEXER_SWITCHTYPE=>1; SessionPropertyConstants::MULTIPLEXER_SWITCHTIMEOUT=>5000)); echo $session->getSessionId(); ?> ?>2.I did create a foder named SDK and placed the following components/files inside:
/OpenTokSDK.php';  SessionPropertyConstants.phpSessionPropertyConstants.phpIm new with php, could someone help me?the aplication.js script is below:// Place your application-specific JavaScript functions and classes here// This file is automatically included by javascript_include_tag :defaults
var videos = 1;
var publisher; var publisherObj;
var subscribers = {}; var subscriberObj = {};
var MAX_WIDTH_VIDEO = 264; var MAX_HEIGHT_VIDEO = 198;
var MIN_WIDTH_VIDEO = 200; var MIN_HEIGHT_VIDEO = 150; var MAX_WIDTH_BOX = 800; var MAX_HEIGHT_BOX = 600;
var CURRENT_WIDTH = MAX_WIDTH_VIDEO; var CURRENT_HEIGHT = MAX_HEIGHT_VIDEO; function sessionConnectedHandler(event) { publish(); for (var i = 0; i < event.streams.length; i++) { addStream(event.streams[i]); } }
function streamCreatedHandler(event) { for (var i = 0; i < event.streams.length; i++) { addStream(event.streams[i]); } }
function streamDestroyedHandler(event) { videos--; layoutManager(); }

function exceptionHandler(event) {    alert("Exception msg:" + event.message + "title: " + event.title + " code: " + event.code); }
//-------------------------------------- //  HELPER METHODS //-------------------------------------- function addStream(stream) { // Check if this is the stream that I am publishing. If not // we choose to subscribe to the stream. if (stream.connection.connectionId == session.connection.connectionId) { return; }
var div = document.createElement('div'); // Create a replacement div for the subscriber var divId = stream.streamId; // Give the replacement div the id of the stream as its id div.setAttribute('id', divId); document.getElementById("videobox").appendChild(div); subscriberObj[stream.streamId] = div;  subscribers[stream.streamId] = session.subscribe(stream, divId, {"width": CURRENT_WIDTH, "height": CURRENT_HEIGHT});
videos++; layoutManager(); }
function publish() { if (!publisher) { var parentDiv = document.getElementById("videobox"); publisherObj = document.createElement('div'); // Create a replacement div for the publisher publisherObj.setAttribute('id', 'opentok_publisher'); parentDiv.appendChild(publisherObj); publisher = session.publish('opentok_publisher', {"width": CURRENT_WIDTH, "height": CURRENT_HEIGHT}); } } function layoutManager() { var estBoxWidth = MAX_WIDTH_BOX / videos; var width = Math.min(MAX_WIDTH_VIDEO, Math.max(MIN_WIDTH_VIDEO, estBoxWidth)); var height = 3*width/4; publisherObj.height = height; publisherObj.width = width; for(var subscriberDiv in subscriberObj) { subscriberDiv.height = height; subscriberDiv.width = width; } CURRENT_HEIGHT = height; CURRENT_WIDTH = width; }
Was this post helpful? (0)
intel
 

working with php - api

Postby jtsai » Tue Aug 09, 2011 1:15 pm

Code: Select all
Archived Post


Hi intel

Does your server support PHP? Try creating a "test.php" with this as the code:

<?php phpinfo(); ?>

It should produce a bunch of information if you point your browser to the page. If it doesn't, it means PHP isn't supported on your server.

Thanks,
John
Was this post helpful? (0)
jtsai
 

working with php - api

Postby intel » Wed Aug 10, 2011 12:28 am

Code: Select all
Archived Post


Thanks  a lot John, the <?php   phpinfo() ?> did work corectly:PHP is supported on my server:However did get the pop -up  below after running the code earlier posted:http://forums.tokbox.com/post/printadd?id=5437963this was the browser pop up:

1.Exception message:sessioninfoAPI:: failed to get session info_Error #2170 Title Security error cod:1009.
2.Exception msg:Invalid authentication passed in session.connect().Failed to pass the Token.No sentinel for version T1== found in token <?php print $apiObj->generate_token(sessionId);?>title:Authentication error code:1004.sincerely,Moses.
Was this post helpful? (0)
intel
 

working with php - api

Postby jtsai » Wed Aug 10, 2011 10:16 am

Code: Select all
Archived Post


Hi intel,
Looking at your code above, it seems like you modified it incorrectly. Try starting with a clean download again:
1. Download (http://www.tokbox.com/v0.91.22/sdks/ope ... -08-07.zip)
2. Extract the files into a folder called "SDK".
3. Upload the folder onto your server.
4. Move "SDK/sample/createsession.php" into the same directory "SDK" isex: move "yoursite.com/tokbox/SDK/sample/createSession.php" to "yoursite.com/tokbox/createSession.php"
5. Grab an API key from here: (http://www.tokbox.com/opentok/api/tools/js/apikey)
6. You will receive an email with a key and secret. Modify your SDK/API_Config.php by filling in the API_KEY and API_SECRET with the appropriate values
7. Open yoursite.com/tokbox/createSession.php with your browser. You should see a session ID and the a token on the page
Note: You don't change any of the files in the server-side library besides moving createSession.php and modifying API_Config.php
Hopefully this helps,John
Was this post helpful? (0)
jtsai
 

working with php - api

Postby amolbhandari52 » Tue Sep 13, 2011 3:25 am

Code: Select all
Archived Post


John i tried doing the 7steps which you gave. but i am geeting following error:


Fatal error: Uncaught exception 'OpenTokException' with message 'Failed to create session: Invalid response from server' in C:\xampp\htdocs\SDK\OpenTokSDK.php:80 Stack trace: #0 C:\xampp\htdocs\js_getting_started.php(11): OpenTokSDK->create_session('127.0.0.1', Array) #1 {main} thrown in C:\xampp\htdocs\SDK\OpenTokSDK.php on line 80
Was this post helpful? (0)
amolbhandari52
 

working with php - api

Postby jtsai » Wed Sep 14, 2011 12:41 pm

Code: Select all
Archived Post


Which version of PHP do you have?
John
Was this post helpful? (0)
jtsai
 

Re: working with php - api

Postby pbcomput » Sat Dec 10, 2011 10:28 am

jtsai wrote:
Code: Select all
Archived Post


Hi intel,
Looking at your code above, it seems like you modified it incorrectly. Try starting with a clean download again:
1. Download (http://www.tokbox.com/v0.91.22/sdks/ope ... -08-07.zip)
2. Extract the files into a folder called "SDK".
3. Upload the folder onto your server.
4. Move "SDK/sample/createsession.php" into the same directory "SDK" isex: move "yoursite.com/tokbox/SDK/sample/createSession.php" to "yoursite.com/tokbox/createSession.php"
5. Grab an API key from here: (http://www.tokbox.com/opentok/api/tools/js/apikey)
6. You will receive an email with a key and secret. Modify your SDK/API_Config.php by filling in the API_KEY and API_SECRET with the appropriate values
7. Open yoursite.com/tokbox/createSession.php with your browser. You should see a session ID and the a token on the page
Note: You don't change any of the files in the server-side library besides moving createSession.php and modifying API_Config.php
Hopefully this helps,John


Hi John,

I did all the things which you explain above.

it generated session id - 2_MX44ODkzMjMyfjExNy4xOTguMTYxLjE2NH4yMDExLTEyLTEwIDE3OjE4OjAwLjcyNDc1OCswMDowMH4wLjIyOTc0MDc2MTY4Nn4

when I put this session id in my code it gives me error.

I dnt know where I am going wrong.

please help me out.

Thanks,
Palak
Was this post helpful? (0)
pbcomput
 
Posts: 91
Joined: Sat Dec 10, 2011 10:11 am
Thumbs Up: 0

Re: working with php - api

Postby jtsai » Mon Dec 12, 2011 11:53 am

pbcomput wrote:Hi John,

I did all the things which you explain above.

it generated session id - 2_MX44ODkzMjMyfjExNy4xOTguMTYxLjE2NH4yMDExLTEyLTEwIDE3OjE4OjAwLjcyNDc1OCswMDowMH4wLjIyOTc0MDc2MTY4Nn4

when I put this session id in my code it gives me error.

I dnt know where I am going wrong.

please help me out.

Thanks,
Palak


What error are you receiving? Can you copy and paste it or give a screen shot? Are you also giving the token thats associated with the session id?

John
Was this post helpful? (0)
User avatar
jtsai
 
Posts: 4541
Joined: Wed Sep 14, 2011 3:00 pm
Thumbs Up: 195

Re: working with php - api

Postby pbcomput » Tue Dec 13, 2011 11:39 am

jtsai wrote:What error are you receiving? Can you copy and paste it or give a screen shot? Are you also giving the token thats associated with the session id?

John


Hi,

thanks for your help. I was working with php sdk but now I combine php sdk with javascript and its working now.

Thanks for your help. :)
Was this post helpful? (0)
pbcomput
 
Posts: 91
Joined: Sat Dec 10, 2011 10:11 am
Thumbs Up: 0


Return to Supported Server API (PHP, Java, Ruby, Python)



Who is online

Users browsing this forum: No registered users and 1 guest

cron