Get started
  • English
  • 简体中文
Official Site
Get started
  • English
  • 简体中文
Official Site
  • Get started
  • Concepts
  • Guides
  • Device capabilities & events
  • API reference
    • Public conventions
    • Development specification
    • accessToken: Get administrator token
    • API request example
    • Return codes
    • Interface call limits
    • Account docking
      • OAuth authorization
        • oauthTokenV2: Exchange or refresh OAuth tokens
        • getStreamUrl: Get RTSP stream URL
      • createSubAccount: Create Sub Account
      • getOpenIdByAccount: Get openid based on sub-account
      • deleteSubAccount: Delete subaccount
      • listSubAccount: Get the list of sub-accounts
      • subAccountToken: Get subaccount token
      • addPolicy: Add sub-account permissions
      • clearPolicy: Clear sub-account authorization policy
      • queryDevicePermission: Sub-account device dimension permission
      • deleteDevicePermission: Delete sub-account device permission
      • listSubAccountDevice: Query the list of devices with permissions for the sub-account
    • Device APIs
    • Device live broadcast
    • Push configuration
    • Cloud storage service
    • Resource pool quota
    • Legacy APIs (deprecated)
  • SDK and tools
  • Solutions
  • Platform and support
On this page
Function details
Request address
Authentication
Grant type: authorization_code
Grant type: refresh_token
Response (success)
Error responses
Related
Error codes

oauthTokenV2: Exchange or refresh OAuth tokens

oauthTokenV2: Exchange or refresh OAuth tokens

Function details

Obtain or refresh the end user's OAuth access token after H5 authorization. This endpoint uses form-urlencoded body and HTTP Basic authentication with the OAuth project Access Key and Secret Key — not the standard Open API JSON body with system / params / id.

See OAuth 2.0 authorization for the authorization code callback flow.

Request address

POST https://openapi-[DataCenter].easy4ip.com/openapi/oauthTokenV2

Replace [DataCenter] with your developer account data center (see Development specification).

Authentication

HeaderValue
AuthorizationBasic + Base64(ProjectAccessKey:ProjectSecretKey)
Content-Typeapplication/x-www-form-urlencoded

Reference: RFC 2617 §2 (HTTP Basic).

Grant type: authorization_code

Exchange the authorization code from the callback URL for tokens.

Form body

ParameterRequiredDescription
grant_typeYesauthorization_code
codeYesAuthorization code from the callback code query parameter
redirect_uriNoOptional. Same callback URL as configured for the OAuth project. The Open Platform token endpoint does not validate this field; send it only if your client or authorization server requires it.

Sample request

POST /openapi/oauthTokenV2 HTTP/1.1
Host: openapi-fk.easy4ip.com
Authorization: Basic <base64(ProjectAccessKey:ProjectSecretKey)>
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=XXXXXXXXXXXXXXXXXX&redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb

Grant type: refresh_token

Refresh the access token before expires_in elapses.

Form body

ParameterRequiredDescription
grant_typeYesrefresh_token
refresh_tokenYesrefresh_token from a prior successful response

Sample request

POST /openapi/oauthTokenV2 HTTP/1.1
Host: openapi-fk.easy4ip.com
Authorization: Basic <base64(ProjectAccessKey:ProjectSecretKey)>
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token&refresh_token=QWU3723JDDUFH2382

Response (success)

HTTP 200, Content-Type: application/json;charset=UTF-8, Cache-Control: no-store, Pragma: no-cache.

FieldTypeDescription
access_tokenStringEnd user access token (Ot_ prefix), bearer type
token_typeStringbearer
expires_inNumberLifetime in seconds (7200)
refresh_tokenStringUse for the next refresh grant
scopeStringCurrent value all

Sample response

{
  "access_token": "Ot_xxxxxxxxxxxxxxxxxx",
  "token_type": "bearer",
  "expires_in": 7200,
  "refresh_token": "QWU3723JDDUFH2382",
  "scope": "all"
}

Error responses

This endpoint uses the OAuth 2.0 token error format, not the standard Open API result JSON layout. On failure the HTTP status is typically 200 or 400 and the body is JSON with an error field.

errorWhen
invalid_requestMissing or empty grant_type, code, or refresh_token; malformed Authorization header
invalid_clientUnknown OAuth project Access Key / Secret Key, or token exchange failed
unsupported_grant_typegrant_type is not authorization_code or refresh_token

Related

  • Development specification
  • getStreamUrl
  • OAuth authorization module

Error codes

This method may return the codes below. See Return codes and Capability errors for the full catalog.

Gateway and auth (SN / TK / OP)

CodeMeaningNext step
SN1001Signature errorCheck sign per Development specification
TK1002Token invalid or expiredRefresh accessToken
OP1002Missing required parameterAdd required fields
OP1003Invalid parameterMatch this page’s parameter table
OP1009Permission deniedCheck token and device bind/share grants
OP1013Total call limit exceededReduce call rate
OP1014Daily per-interface limit exceededSee Interface call limits
DV1007Device offlineWait until the device is online

See Return codes · OP/SN/TK for the full catalog.

Sub-accounts (SUB)

CodeMeaningNext step
SUB1001–SUB1002Sub-account lacks API permissionUpdate policy via addPolicy
SUB1005Sub-account token expiredRefresh subAccountToken
SUB1006No device grant for sub-accountCheck Resource and device serial
SUB1008Sub-account not bound to appCreate and bind the sub-account first

See Return codes · SUB.

Interface call limits
getStreamUrl: Get RTSP stream URL