screenleap api中的javascript强制数据错误

screenleap api中的javascript强制数据错误,javascript,php,json,api,screensharing,Javascript,Php,Json,Api,Screensharing,我在一个名为$json的变量中有一个json编码的数据,它看起来像- string(1243) "{"screenShareCode":"882919360", "appletHtml":"", "presenterParams":"aUsEN5gjxX/3NMrlIEGpk0=", "viewerUrl":"http://api.screenleap.com/v2/viewer/882919360?accountid=mynet", "origin":"API"

我在一个名为$json的变量中有一个json编码的数据,它看起来像-

string(1243) "{"screenShareCode":"882919360", "appletHtml":"", "presenterParams":"aUsEN5gjxX/3NMrlIEGpk0=", "viewerUrl":"http://api.screenleap.com/v2/viewer/882919360?accountid=mynet", "origin":"API"}" }
这是您根据文档实现它的方式


window.onload=函数(){
screenleap.startSharing('DEFAULT',JSON.parse('');
};

如果这不起作用,您必须向screenleap报告。

看起来
$json
是一个字符串,您需要传入一个json对象。请尝试以下操作:

window.onload = function() {
    var screenShareData = '?php echo $json;?>';
        screenleap.startSharing('DEFAULT', JSON.parse(screenShareData));
};

如果要访问这些值,应该只需要实际解析JSON。否则,只需将响应数据直接传递到startSharing函数中,如下所示:

<?php
$url = 'https://api.screenleap.com/v2/screen-shares';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('authtoken:<your authtoken>'));
curl_setopt($ch, CURLOPT_POSTFIELDS, 'accountid=<your accountid>');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);
$json = json_decode($data, true);
?>

<script type="text/javascript" src="http://api.screenleap.com/js/screenleap.js"></script>
<script type="text/javascript">
    window.onload = function() {
        screenleap.startSharing('DEFAULT', <?php echo $data; ?>);
    };
</script>

window.onload=函数(){
screenleap.startSharing('DEFAULT',);
};

如果您只插入自己的accountid和authtoken(不带前导空格),应该可以使用。

它会给出一个错误,说“Expected}”$json已经是json格式的。我已经更新了我的答案,试试看。我认为screenleap需要一个JSON对象,但它看起来需要JSON字符串。javascript错误:“缺少必需的屏幕共享数据”我已经用实现的完整代码更新了我的答案。嗨,我试过了,但是它给了我一个javascript错误,说“Unterminated string constant”。
<?php

// Config
$authtoken = '';
$accountid = '';

// 1. Make CURL Request
$url = 'https://api.screenleap.com/v2/screen-shares';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('authtoken:<authtoken>'));
curl_setopt($ch, CURLOPT_POSTFIELDS, 'accountid=<accountid>');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$json = json_decode($data, true);

?>

<!-- 2. Launch the Presenter App -->
<script type="text/javascript" src="http://api.screenleap.com/js/screenleap.js"></script>
<script type="text/javascript">
    window.onload = function() {
        screenleap.startSharing('DEFAULT', JSON.parse('<?php echo $json; ?>'));
    };
</script>
window.onload = function() {
    var screenShareData = '?php echo $json;?>';
        screenleap.startSharing('DEFAULT', JSON.parse(screenShareData));
};
<?php
$url = 'https://api.screenleap.com/v2/screen-shares';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('authtoken:<your authtoken>'));
curl_setopt($ch, CURLOPT_POSTFIELDS, 'accountid=<your accountid>');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);
$json = json_decode($data, true);
?>

<script type="text/javascript" src="http://api.screenleap.com/js/screenleap.js"></script>
<script type="text/javascript">
    window.onload = function() {
        screenleap.startSharing('DEFAULT', <?php echo $data; ?>);
    };
</script>