Metadata and PHP API

Official OpenTok Server-Side libraries

Metadata and PHP API

Postby jiggles » Mon Aug 22, 2011 10:26 am

Code: Select all
Archived Post


Hi,
I'm having some issues setting metadata with the PHP API.
Just to test it out, I'm using the same values in the example:
Code: Select all
apiObj = new OpenTokSDK(API_Config::API_KEY, API_Config::API_SECRET);
$role = RoleConstants:: PUBLISHER;
$metadata =  '{"username": "bob", "color": "Blue"}';
 $token = $apiObj->generate_token($sessionid,$role);


This works fine, because I'm not pushing the metadata in to the generate_token method. But if I change this to include the metadata like so:
Code: Select all
$token = $apiObj->generate_token($sessionid,$role,$metadata);

I get the following error when trying to connect:
Exception: 1004:: Invalid authentication information passed in Session.connect(). Failed to parse the token: Failed to parse token: too many values to unpack


I had a look at the SDK to see was I calling the method wrong, and it seems that, unlike in the tutorial, the method is actually called with the metadata as the fourth argument, rather than the third.
Code: Select all
public function generate_token($session_id='', $role='', $expire_time=NULL, $connection_data='')


So, I tried changing my call to the generate_token method to:
Code: Select all
$token = $apiObj->generate_token($sessionid,$role,null,$metadata);

But that just gave me the exact same error.
For reference, I'm using SDK version tbphp-v0.91.2011-08-07 and loading the Javascript API on the page from http://static.opentok.com/v0.91/js/TB.min.js and as I mentioned at the start, everything works fine if I don't pass any metadata with the generate_token request.
So is this a bug, or am I just missing something really obvious?
Was this post helpful? (0)
jiggles
 

Metadata and PHP API

Postby jtsai » Mon Aug 22, 2011 11:37 am

Code: Select all
Archived Post


Hi jiggles
Have you tried generating a token with the sessionID and role as empty strings?
$token = $apiObj->generate_token("", "", null, $metadata); Also just to double-check, you are producing a session ID server-side and passing it to the Session.connect() function in the JS, correct?
John
Was this post helpful? (0)
jtsai
 

Metadata and PHP API

Postby jiggles » Mon Aug 22, 2011 1:08 pm

Code: Select all
Archived Post


Hi John,
I've tried passing in empty strings just now and I'm getting the same error when it attempts to connect to the session.
Our use case is actually providing scheduled video meetings, so we create the session when the scheduler runs, then issue the tokens by pulling the session ID from the database, and use the same session ID when establishing the session object in the JS. So while we don't generate it every time we try to make a token, we are using valid session IDs throughout.
I changed the code to make everything be generated fresh on each page load to see if it would narrow down the issue, but it still gave me the same error.
Curiously, though, if I drop the JSON notation for the metadata, the error seems to go away. It appears it doesn't like the colon chararacter.
$metadata =  "{'username' = 'bob', 'color' = 'Blue'}"; Fine$metadata =  "'username' = 'bob', 'color' = 'Blue'"; Fine$metadata =  "username=bob,color=Blue"; Fine$metadata =  "username:bob,color:Blue"; Error$metadata =  "{'username': 'bob', 'color': 'Blue'}"; Error
I'm sure this isn't the intended behaviour, but it's nice to have a easy workaround for now. :)
Also, I could've sworn I tried simple comma-separated name=value pairs when I was tearing my hair out earlier, but I guess not. :sneaky:
Was this post helpful? (0)
jiggles
 

Metadata and PHP API

Postby jtsai » Mon Aug 22, 2011 1:53 pm

Code: Select all
Archived Post


Hi
Do you have the latest server-side library? There was a bug in previous version that doesn't url_encode the connection data. It was fixed in the latest version.  Line 58 of OpenTokSDK.php should have:
$data_string .= "&connection_data=" . urlencode($connection_data);Download the newest version here: http://www.tokbox.com/v0.91.24/sdks/ope ... -08-07.zip
Thanks,John
Was this post helpful? (0)
jtsai
 

Metadata and PHP API

Postby jiggles » Tue Aug 23, 2011 4:13 am

Code: Select all
Archived Post


Huh, weird.
The version I've been using is marked as last modified 2011-08-07 (the version string is  tbphp-v0.91.2011-08-07), but it was missing the urlencode command.
The latest version you've linked though, has it in. I just wasn't downloading it because it looked like I had it up to date. Updated now and it's working fine.
Also, it turns out I did try name=value pairs when I was originally going round in circles yesterday, and it wouldn't work then. Because I only ever tried it when I was plugging the metadata in as the third argument. So the bug in the SDK was hiding the mistake in the tutorial, and the mistake in the tutorial was hiding the bug in the SDK!
All mysteries solved, then.
Cheers for your help, John. :)
Was this post helpful? (0)
jiggles
 

Re: Metadata and PHP API

Postby jansha » Thu Jan 10, 2013 6:18 am

Am getting the following Error message in alert:

ERROR :
Code: Select all
Exception: 1004::Invalid authentication information passed in Session.connect(). Invalid Token: Sentinel missing


The above error occurs while creating the session and token dynamically in PHP SDK

Pls support
Was this post helpful? (0)
jansha
 
Posts: 1
Joined: Wed Jan 09, 2013 5:01 am
Thumbs Up: 0

Re: Metadata and PHP API

Postby jtsai » Fri Jan 11, 2013 11:38 am

jansha wrote:Am getting the following Error message in alert:

ERROR :
Code: Select all
Exception: 1004::Invalid authentication information passed in Session.connect(). Invalid Token: Sentinel missing


The above error occurs while creating the session and token dynamically in PHP SDK

Pls support


All generated tokens should have "T1==" in front of it. Could you give us an example of a token that you generated?

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


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



Who is online

Users browsing this forum: No registered users and 1 guest

cron