我如何使用mixpanel API? [英] How can I use mixpanel API?

查看:115
本文介绍了我如何使用mixpanel API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法连接到mixpanel。

I'm not able to connect to mixpanel.

我尝试使用正确的api_key和api_secret,如下所示:

I have tried with a correct api_key and api_secret, like this:

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

正如您所看到的,我尝试将此API与JSONP一起使用,但我迷失了树木。有没有人知道mixpanel和JSONP?

As you can see, I try to use this API with JSONP, but I'm lost in the woods. Is there anybody who has knowledge about mixpanel and JSONP?

提前谢谢。

编辑:我' ve添加了新版本的页面。

I've added the new version of the page.

推荐答案

来自文档:


我们没有JS客户端库,但我们在
API后端实现了jsonp。有关简要概述,请参阅Wikipedia文章。我们的
jsonp参数是'回调'。
签名计算期间不会使用此参数。

We do not have a JS client library, but we have implemented jsonp on the API backend. See the Wikipedia article for a brief overview. Our jsonp parameter is 'callback'. This parameter will not be used during signature calculation.

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

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

Assuming you calculate the signature correctly, the below example will work:

 $.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);
        });

这篇关于我如何使用mixpanel API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆