我如何使用mixpanel API?

Laj*_*pad 9 javascript jquery jsonp mixpanel

我无法连接到mixpanel.

我试过一个正确的api_key和api_secret,像这样:

<html>
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js" />
    </script>
    <script type="text/javascript" src="faulty-labs-md5.js" />
    </script>
</head>
<body>
    <script type="text/javascript">
$(document).ready(function() {
    $("#btnTest").click(function() {

        var api_key = 'BigSecret';
        var api_secret = 'BigSecret2';
        var expire = new Date('2012', '12', '24').getTime() / 1000 + 3600;
        var from_date = $("#date1").val();
        var to_date = $("#date2").val();
        var sig = faultylabs.MD5("api_key=" + api_key + "expire=" + expire + "from_date=" + from_date + "to_date=" + to_date + api_secret);
        //var path = 'https://data.mixpanel.com/api/2.0/export?api_key=' + api_key + "&expire=" + expire + "&from_date=" + from_date + "&to_date=" + to_date;
        var path = 'https://data.mixpanel.com/api/2.0/export?api_key=' + api_key + "&expire=" + expire + "&from_date=" + from_date;
        path = path + "&sig=" + sig.toLowerCase();
        $.jsonp({
            type: 'GET',
            url: path,
            async: false,
            callback: to_date,  // sneaky bogus shenanigans
            callbackParameter: 'to_date', // more of same
            contentType: "application/json",
            dataType: 'jsonp',
            cache: true,
            success: function(json) {
                alert(json);
            },
            error: function(e) {
                console.log(e.message);
            }
        });
    });
});
    </script>
    <input type="text" id="date1" value="2012-10-29" />
    <input type="text" id="date2" value="2012-10-29" />
    <button onclick="return false" id="btnTest">Test</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我尝试将这个API与JSONP一起使用,但我迷失在树林里.有没有人知道mixpanel和JSONP?

先感谢您.

编辑:我已经添加了新版本的页面.

Gre*_*ean 1

从文档中:

我们没有 JS 客户端库,但我们在 API 后端实现了 jsonp。请参阅维基百科文章以获取简要概述。我们的 jsonp 参数是“回调”。签名计算时不会使用该参数。

https://mixpanel.com/docs/api-documentation/data-export-api#libs-js

假设您正确计算签名,下面的示例将起作用:

 $.getJSON('http://mixpanel.com/api/2.0/segmentation/?callback=?', {
            event: event,
            from_date: from_date,
            to_date: to_date,
            expire: expire,
            sig: sig,
            api_key: api_key
        }, function (result) {
            alert(result);
        });
Run Code Online (Sandbox Code Playgroud)