rest - Clockify API 身份验证
问题描述
我正在尝试按照您的步骤连接到您的 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 进行身份验证和所有操作,但我一直遇到相同的错误/问题。
有什么我想念的吗?
解决方案
- 您不需要
X-Api-Key
用于获取身份验证令牌。 - 看起来 JQuery 想要在发送之前对数据进行序列化,所以只需
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);
}
});
推荐阅读
- jira - 无法配置 Jira 泳道
- machine-learning - TypeError:在 SVM 中的 'tuple' 和 'int' 实例之间不支持 '<'
- spring-boot - Redis spring boot如何从命令行查看值
- .net - TFS 2012 express 可以与 Visual Studio 2005 一起使用吗?
- c++ - Sphere在线评委(生命、宇宙、万物)
- email - 直接从应用程序发送电子邮件,无需打开选择器 (Kotlin)
- javascript - 反应原生:制作动画箭头到手风琴列表的方法是什么?
- python-3.x - 遍历行时如何为“底图”子图设置固定大小?
- python - 在 Pycharm 上为 Ubuntu 20.04 安装 wxPython
- sql - 给定每日每小时数据,如何在 SQL Server 中从上午 8 点到晚上 8 点平均 12 小时范围内的每小时间隔数据?