我尝试将“导出原始数据”端点与“https://data.mixpanel.com/api/2.0/export/”一起使用'
但是注意是工作...... 我尝试了很多请求和自由 - 导出端点没有任何作用
我的代码:
$.ajaxPrefilter( function (options) {
if (options.crossDomain && jQuery.support.cors) {
var http = (window.location.protocol === 'http:' ? 'http:' : 'https:');
options.url = http + '//cors.now.sh/' + options.url;
}
});
mixpanel_base_uri = "https://data.mixpanel.com/api/2.0" ;
proxy = "" // "https://cors-anywhere.herokuapp.com/"
var ajaxRequest = $.ajax({
url : "" + mixpanel_base_uri + "/" + end_point + "/?",
data: args,
dataType: "text",
processData: true,
headers:{
// "Access-Control-Allow-Credentials" : true,
// "Access-Control-Allow-Methods": "GET, OPTIONS",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*"
// ('Authorization', 'Basic ' + btoa(api_secret+ ':' +'')),
},
xhrFields: {
// Getting on progress streaming response
withCredentials: true,
onprogress: function(e)
{
console.log(e)
// var progressResponse;
// var response = e.currentTarget.response;
// if(lastResponseLength === false)
// {
// progressResponse = response;
// lastResponseLength = response.length;
// }
// else
// {
// progressResponse = response.substring(lastResponseLength);
// lastResponseLength = response.length;
// }
// console.log(response)
}
}
});
// On completed
ajaxRequest.done(function(data) {
console.log('Complete response = ' + data);
});
// On failed
ajaxRequest.fail(function(error){
console.log('Error: ', error);
});
我尝试使用“node-mixpanel-export.js”和“mixpanel-data-export”自由主义者,但它们不起作用
我收到很多错误(每次都有不同的错误) 来自:
Access to XMLHttpRequest at 'https://data.mixpanel.com/api/2.0/export/?&from_date=01-08-2019&to_date=01-09-2019'
from origin 'http://localhost:8888' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
mixpanel_connector.js:129
和:
To authenticate your request, you must use your API Secret in the HTTP authorization header
当我添加身份验证时事件仍然不起作用..
有人可以帮助我吗?或者有我可以理解的有效代码
谢谢。
------更新------
我解决了几乎所有问题,但我无法通过授权问题,什么都不起作用..也许我错过了什么?
var obj = new XMLHttpRequest();
var params = JSON.stringify(args);
obj.onreadystatechange = function() {
if (obj.readyState == 4 && obj.status == "200"){
console.log(obj)
doneCallback();
}
}
obj.open("GET",mixpanel_base_uri + end_point);
obj.setRequestHeader('Authorization', 'Basic ' + base64Encode(this.api_secret + ':'));
obj.setRequestHeader("Content-type", "application/json; charset=utf-8");
obj.send(params);
但仍然遇到同样的错误:
To authenticate your request, you must use your API Secret in the HTTP authorization header
最佳答案
问题在于授权。
通过混合面板:
To make an authorized request, put your project's API Secret in the "username" field of the Basic access authentication header. Make sure you use HTTPS and not HTTP - as our API rejects requests made over HTTP. Sending over HTTP can expose your API Secret.
Client Libraries
问题是 JavaScript 中的“bota”函数没有返回正确的哈希值 只需将其更改为其他哈希函数
关于javascript - Mixpanel - 身份验证问题,javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57757236/