我正在尝试按照您的步骤连接到您的API,但是我真的不确定如何启动身份验证... 最初的尝试是通过AJAX进行Javascript通信,因此这是它的代码:
$.ajax({
url: 'https://api.clockify.me/api/auth/token/',
method: 'POST',
cache: false,
contentType: 'application/json',
headers: {
'X-Api-Key': 'MyAPIKey'
},
data: { "email": "MyMail", "password": "MyPass" },
always: function(r){
console.log(r);
}
});
始终在响应时出现如下错误:
{"message":"Could not read document: Unrecognized token 'email': was expecting ('true', 'false' or 'null')\n at [Source: java.io.PushbackInputStream@5cfd6511; line: 1, column: 7]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'email': was expecting ('true', 'false' or 'null')\n at [Source: java.io.PushbackInputStream@5cfd6511; line: 1, column: 7]","code":3002}
接下来,我尝试继续并从PHP开始通信,并使用CURL进行身份验证和所有操作,但是我一直遇到相同的错误/问题。
也许我想念什么吗?
答案 0 :(得分:1)
X-Api-Key
来获取身份验证令牌。JSON.stringify
,如本例所示:$.ajax({
url: 'https://api.clockify.me/api/auth/token/',
method: 'POST',
contentType: "application/json",
data: JSON.stringify({
email: "someone@example.com",
password: "secretpass"
}),
always: function(r) {
console.log(r);
}
});