试图让我的xAPI语句动态化

时间:2016-11-21 21:31:29

标签: tin-can-api

我有一个应用程序,其中有人使用他们的全名和电子邮件地址登录。我使用HTML5的本地存储捕获该信息。我想使用xAPI Youtube视频跟踪器向LRS发送消息。我在将本地存储变量放入actor语句的代码时遇到问题。当我硬编码名称和电子邮件地址时,它工作正常。当我尝试从本地存储中取出时,它说“没有办法。”#34;你能看看我违规的代码并告诉我哪里出错了吗?我评论了什么是有效的,什么不起作用就在它下面。非常感谢。

var name = localStorage.getItem('name');
    var email = localStorage.getItem('email');  
    var video = "RXsHnGyVddg"; // Change this to your video ID

    // "global" variables read by ADL.XAPIYoutubeStatements
    ADL.XAPIYoutubeStatements.changeConfig({
      //"actor":  {"mbox":"mailto:molly.fisher@example.com", "name":"Molly Fisher"},
      "actor":  {"mbox":"mailto:" + email, "name": + name},
      "videoActivity": {"id":"https://www.youtube.com/watch?v=" + video, "definition":{"name": {"en-US":video}} }
    });

    function initYT() {
      var tag = document.createElement('script');
      tag.src = "https://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
    }

    var player;
    function onYouTubeIframeAPIReady() {
      player = new YT.Player('player', {
        height: '390',
        width: '640',
        videoId: video,
        playerVars: { 'autoplay': 0 },
        events: {
          'onReady': ADL.XAPIYoutubeStatements.onPlayerReady,
          'onStateChange': ADL.XAPIYoutubeStatements.onStateChange
        }
      });
    }

    initYT();


    // Auth for the LRS
    var conf = {
        "endpoint" : "https://lrs.adlnet.gov/xapi/",
        "auth" : "Basic " + toBase64("xapi-tools:xapi-tools"),
    };

    ADL.XAPIWrapper.changeConfig(conf);

    /*
     * Custom Callbacks
     */
    ADL.XAPIYoutubeStatements.onPlayerReadyCallback = function(stmt) {
      console.log("on ready callback");
    }

    // Dispatch Youtube statements with XAPIWrapper
    ADL.XAPIYoutubeStatements.onStateChangeCallback = function(event, stmt) {
      console.log(stmt);
      if (stmt) {
        stmt['timestamp'] = (new Date()).toISOString();
        ADL.XAPIWrapper.sendStatement(stmt, function(){});
      } else {
        console.warn("no statement found in callback for event: " + event);
      }
    }

0 个答案:

没有答案