I am new to PHP and trying to a third party code namely Big blue button api https://github.com/bigbluebutton/bigbluebutton/tree/master/labs/bbb-api-php
I try to call BigBlueButton->createMeeting()
function which looks like this :
public function createMeeting($createMeetingParams, $xml = '')
{
$xml = $this->processXmlResponse($this
->getCreateMeetingURL($createMeetingParams), $xml);
//$xml is fine
return new CreateMeetingResponse($xml);
}
CreateMeetingResponse class
namespace BigBlueButton\Responses;
/**
* Class CreateMeetingResponse
* @package BigBlueButton\Responses
*/
class CreateMeetingResponse extends BaseResponse
{
/**
* @return string
*/
public function getMeetingId()
{
return $this->rawXml->meetingID->__toString();
}
/**
* @return string
*/
public function getAttendeePassword()
{
return $this->rawXml->attendeePW->__toString();
}
/**
* @return string
*/
public function getModeratorPassword()
{
return $this->rawXml->moderatorPW->__toString();
}
/**
* Creation timestamp.
*
* @return double
*/
public function getCreationTime()
{
return doubleval($this->rawXml->createTime);
}
/**
* @return int
*/
public function getVoiceBridge()
{
return intval($this->rawXml->voiceBridge);
}
/**
* @return string
*/
public function getDialNumber()
{
return $this->rawXml->dialNumber->__toString();
}
/**
* Creation date at the format "Sun Jan 17 18:20:07 EST 2016".
*
* @return string
*/
public function getCreationDate()
{
return $this->rawXml->createDate->__toString();
}
/**
* @return true
*/
public function hasUserJoined()
{
return $this->rawXml->hasUserJoined->__toString() == 'true';
}
/**
* @return int
*/
public function getDuration()
{
return intval($this->rawXml->duration);
}
/**
* @return bool
*/
public function hasBeenForciblyEnded()
{
return $this->rawXml->hasBeenForciblyEnded->__toString() == 'true';
}
/**
* @return string
*/
public function getMessageKey()
{
return $this->rawXml->messageKey->__toString();
}
/**
* @return string
*/
public function getMessage()
{
$this->rawXml->message->__toString();
}
}
BaseResponse class
namespace BigBlueButton\Parameters;
/**
* Class BaseParameters.
*/
abstract class BaseParameters
{
/**
* @param $array
*
* @return string
*/
protected function buildHTTPQuery($array)
{
return http_build_query(array_filter($array));
}
/**
* @return string
*/
abstract public function getHTTPQuery();
}
Now when I do call the BigBlueButton->createMeeting()
function, I am expecting an object which I can encode to json ,But what I get is this (I have used print_r()
here..):
BigBlueButton\Responses\CreateMeetingResponse Object
(
[rawXml:protected] => SimpleXMLElement Object
(
[returncode] => FAILED
[messageKey] => idNotUnique
[message] => A meeting already exists with that meeting ID. Please use a different meeting ID.
)
)
I am not sure what is happening but I think the prefixed namespace 'BigBlueButton\Responses\CreateMeetingResponse Object
' is the problem. I want to parse the response I get to an json object in php but cannot
Here is where I try to parse it
function easymeet_create_meeting($id) {
// Create BBB object
$bbb = new BigBlueButton\BigBlueButton();
//creating meeting parameter
$meetingParas=new BigBlueButton\Parameters\CreateMeetingParameters('123456','sned');
//Creatign meeting
return json_encode($bbb->createMeeting($meetingParas));
///print_r($bbb->createMeeting($meetingParas)) give the xml response shown above
}
The return part looks right. The error you are getting is coming from BigBlueButton->createMeeting()
You already have created a meeting with the ID you used. Are you generating a new Meeting ID to pass in with the XML when you create a new meeting?
Edit:
To be able to json_encode the response you will need to use the getRawXml()
function since $rawXml
is a protected property of the base class and the rest of the class is just methods. So:
public function createMeeting($createMeetingParams, $xml = '')
{
$xml = $this->processXmlResponse($this
->getCreateMeetingURL($createMeetingParams), $xml);
//$xml is fine
$resp = new CreateMeetingResponse($xml);
return $resp->getRawXml();
}
Should return just the SimpleXMLElement
which you can then json_encode.