【发布时间】:2012-10-19 20:55:21
【问题描述】:
我无法连接到 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>
如您所见,我尝试将此 API 与 JSONP 一起使用,但我迷失了方向。有谁了解mixpanel和JSONP的吗?
提前谢谢你。
编辑:我添加了新版本的页面。
【问题讨论】:
-
你能告诉我们更多像控制台是否返回任何东西吗?您是否检查过您的控制台 Ajax 请求是否已发送出去?你什么时候打电话 sendRequestToPage() ?它不会自行启动。
-
我现在收到 {"error": "Invalid API signature"}
-
你没有在你的 url 中指定 api_secret
-
我创建了一个 Javascript 库来让这变得非常简单:github.com/michaelcarter/mixpanel-data-export-js
-
@stealthysnacks 我认为您可以使用代理。您的 Javascript 代码可以向您的服务器发送请求,从而触发您的服务器向 MixPanel 发送请求。这种方式的 API 机密只有您的服务器知道,并且永远不会提供给您的客户端。
标签: javascript jquery jsonp mixpanel