获取访问Token

任何需要访问监控宝API的应用首先需要注册成为监控宝的API客户端用户,注册完毕之后,API客户端会获得:

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

通过下面的地址获取AccessToken:

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

请求参数:

    {
        "grant_type":"password",
        "username":"test@jiankongbao.com",
        "password":"e10adc3949ba59abbe56e057f20f883e",
        "client_id":"demo_id",
        "client_secret":"demo_secret"
    }
    
参数 参数说明
grant_type 必选参数,必须是 password
username 必选参数,用户的监控宝帐号邮箱,例如: test@jiankongbao.com
password 必选参数,用户监控宝帐号的密码,使用md5加密,例如: e10adc3949ba59abbe56e057f20f883e
client_id 必选参数,注册的客户端Id
client_secret 必须参数,注册的客户端密码

* 发送的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 用户帐号验证失败

Token过期后,通过下面的地址获取刷新AccessToken:

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

请求参数:

    {
        "grant_type":"refresh_token",
        "client_id":"demo_id",
        "client_secret":"demo_secret",
        "refresh_token":"a5827ee761c77e169a86643baa970cef33cc8c55",
    }
    
参数 参数说明
grant_type 必选参数,必须是 refresh_token
client_id 必选参数,注册的客户端Id
client_secret 必须参数,注册的客户端密码
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 验证失败)
    }