- Posts: 62
- Thank you received: 3
Ask the community, share ideas, and connect with other LimeSurvey users!
require_once 'jsonRPCClient.php'; define( 'LS_BASEURL', 'https://pathTo/limeSurvey/'); define( 'LS_USER', 'admin' ); define( 'LS_PASSWORD', 'password' ); define( 'LS_DB_HOST', 'localhost' ); define( 'LS_DB_NAME', 'limesurveyDB' ); define( 'LS_DB_USER', 'limesurveyuser' ); define( 'LS_DB_PASS', 'password' ); define( 'LS_DB_TABLEPREFIX', 'lime_' ); $iSurveyID = $_GET["iSurveyID"]; $token = $_GET["token"]; // Instantiate a new RPC client $myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' ); // Get a session key $sSessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD ); // Define some params $aTokenQueryProperties = array('token'=>$token); $aTokenProperties = array('email', 'firstname', 'lastname', 'token', 'tid'); $participantProperties = $myJSONRPCClient->get_participant_properties( $sSessionKey, $iSurveyID, $aTokenQueryProperties, $aTokenProperties); // Print the results echo '<ul> <li>Token ID: '.$participantProperties['tid'].'</li> <li>Email: '.$participantProperties['email'].'</li> <li>First name: '.$participantProperties['firstname'].'</li> <li>Last name: '.$participantProperties['lastname'].'</li> <li>Token - '.$participantProperties['token'].'</li> </ul>'; // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey );
I don't understand the question. My example does use the token to retrieve the participant properties.... there is a way to call this get_participant_properties directly using the TOKEN?
The version is 2.50+ Build 160620tpartner wrote: My example is for version 2.5. What version are you using?
<?php error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); echo "test page to show data: <br>"; require_once 'Classes/jsonRPCClient.php'; include('/sw/LimeSurvey/config.php'); // file wehere I have sotred LS_PASSWORD,LS_USER,LS_BASEURL $iSurveyID = $_GET["iSurveyID"]; $token = $_GET["token"]; echo "received survey ID:".$iSurveyID."<br>"; echo "received token:".$token; // Instantiate a new RPC client $myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/admin/remotecontrol' ); // Get a session key $sSessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD ); // Define some params $aTokenQueryProperties = array('token'=>$token); $aTokenProperties = array('email', 'firstname', 'lastname', 'token', 'tid'); $participantProperties = $myJSONRPCClient->get_participant_properties( $sSessionKey, $iSurveyID, $aTokenQueryProperties, $aTokenProperties); echo "<br>"; print_r ($participantProperties); echo "<br>"; // Print the results echo '<ul> <li>Token ID: '.$participantProperties['tid'].'</li> <li>Email: '.$participantProperties['email'].'</li> <li>First name: '.$participantProperties['firstname'].'</li> <li>Last name: '.$participantProperties['lastname'].'</li> <li>Token - '.$participantProperties['token'].'</li> </ul>'; // Release the session key $myJSONRPCClient->release_session_key( $sSessionKey ); ?>
// Find the TID of a token $aConditions = array('token' => $token); $participants = $myJSONRPCClient->list_participants($sSessionKey, $iSurveyID, 0, 1, true, '', $aConditions); $tid = $participants[0]['tid']; echo 'TID: '.$tid;
I try also on another ( little bit older ) installation of limesurvey, and works in the same way using TID instead token.tpartner wrote: I'm sorry, I cannot help with that error because I cannot reproduce it.
If you need to use the TID, you can access it via the list_participants() method .
Code:// Find the TID of a token $aConditions = array('token' => $token); $participants = $myJSONRPCClient->list_participants($sSessionKey, $iSurveyID, 0, 1, true, '', $aConditions); $tid = $participants[0]['tid']; echo 'TID: '.$tid;