客户端注册之后,可以凭借从监控宝获得的客户端ID和客户端密码来获取用于访问监控宝API服务的AccessToken和RefershToken。

  • AccessToken:访问监控宝API服务需要的Token,该Token对应于每个授权的客户端的每个监控宝用户

  • RefreshToken:在AccessToken过期之后,用于刷新AccessToken


一、获取AccessToken

通过下面的地址获取AccessToken:

https://api.jiankongbao.com/v2/oauth/token.json

请求参数:

参数

参数说明

grant_type

必填,固定为字符串:password

username

必填,用户的监控宝帐号邮箱,例如: test@jiankongbao.com

password

必填,用户监控宝帐号的密码,使用md5加密,例如:

e10adc3949ba59abbe56e057f20f883e

client_id

必填,API客户端ID

client_secret

必填,API客户端密码

* 发送的HTTP请求必须是POST方式,例如:

curl -s https://api.jiankongbao.com/v2/oauth/token.json --data "grant_type=password&username=test@jiankongbao.com&password=e10adc3949ba59abbe56e057f20f883e&client_id=demo_id
&client_secret=demo_secret"

请求成功返回结果:

{
"access_token":"c699242331bf041b57d207f6e410358c1a896e9d",
"expires_in":3600,  (token过期时间,单位秒)
"token_type":"bearer",
"scope":null,
"refresh_token":"a5827ee761c77e169a86643baa970cef33cc8c55"
}

请求失败返回结果:

{
"error":"invalid_client",  
"error_description":"The client credentials are invalid"
}

错误列表:

错误代码

错误说明

invalid_client

客户端ID验证失败

invalid_grant

用户帐号验证失败


二、获取刷新AccessToken

通过下面的地址获取刷新AccessToken:

https://api.jiankongbao.com/v2/oauth/token.json

请求参数:

参数

参数说明

grant_type

必填,固定为字符串:refresh_token

client_id

必填,API客户端ID

client_secret

必填,API客户端密码

refresh_token

必填,当成功获取AccessToken的时候,返回结果里的refresh_token。例如:

a5827ee761c77e169a86643baa970cef33cc8c55

* 发送的HTTP请求必须是POST方式,例如:

curl -s https://api.jiankongbao.com/v2/oauth/token.json --data "grant_type=refresh_token&client_id=demo_id&client_secret=demo_secret&refresh_token=a5827ee761c77e169a86643baa970cef33cc8c55"

请求成功返回结果:

{
"access_token":"c699242331bf041b57d207f6e410358c1a896e9d",     
"expires_in":3600  (token过期时间,单位秒)                       
"token_type":"bearer",
"scope":null,
"refresh_token":"a5827ee761c77e169a86643baa970cef33cc8c55"
}

请求失败返回结果:

{
"error":"invalid_grant",
"error_description":"Invalid refresh token" (refresh token 验证失败)                       
}