0

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

    字符串(1243)“{“screenShareCode”:“882919360”,
    "appletHtml":"",
    "presenterParams":"aUsEN5gjxX/3NMrlIEGpk0=",
    "viewerUrl":"http://api.screenleap.com/v2/viewer/882919360?accountid=mynet",
    "起源":"API"}"
    }

我需要将此 json 数据传递给 javascript 函数,请参见下文

    脚本类型="text/javascript" src="http://api.screenleap.com/js/screenleap.js">/script>
    脚本类型="文本/javascript">
      window.onload = 函数(){
    var screenShareData = '?php echo $json;?>';
        screenleap.startSharing('DEFAULT', screenShareData);
      };
    /脚本>

当我尝试运行此代码时,它给我一个错误,说“缺少强制性屏幕共享数据”
如何解决这个错误?

i am following "https://www.screenleap.com/api/presenter"
4

3 回答 3

0

这是您根据文档实现它的方式

https://www.screenleap.com/api/presenter

<?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>

如果这不起作用,您必须将其报告给screenleap。

于 2013-11-12T12:23:29.247 回答
0

如果您想访问这些值,您应该只需要实际解析 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>

如果您只是插入自己的 accountid 和 authtoken(没有前导空格),那应该适合您。

于 2013-11-14T00:20:12.267 回答
0

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

window.onload = function() {
    var screenShareData = '?php echo $json;?>';
        screenleap.startSharing('DEFAULT', JSON.parse(screenShareData));
};
于 2013-11-12T23:10:32.977 回答