Text Check

Parameter specification

  • Request URL:

https://tsafe.ilivedata.com/api/v1/text/check

  • HTTP request Header:
Header Value Property Description
Content-Type application/json;charset=UTF-8 Required Request body type
Accept application/json;charset=UTF-8 Required Return type accepted
X-AppId Required The only identifier of the project or application.
X-TimeStamp Required The UTC timestamp of the request. Timestamps need to be formatted according to W3C standards, for example: 2010-01-31T23:59:59Z. (http://www.w3.org/TR/xmlschema-2/#dateTime).
Authorization Required Signature value
  • Request method: POST

  • Request body JSON:

Parameter Property Type Description
content Required String The text to be detected. This text is UTF-8 encoded strings with no more than 2048 characters.
strategyId Optional String Policy number. The default policy DEFAULT is used when not passed.
country Optional String country The default policy DEFAUL is used when not passed.
userId Optional String Unique end user ID. The userID should be no more than 64 characters.
sessionId Optional String sessionId,The sessionId should be no more than 64 characters.
receiverId Optional String receiverId,The receiverId should be no more than 64 characters.
userName Optional String User name, nickname. The user name should be no more than 32 characters.
userLevel Optional Number User level
totalPay Optional Number User total payment. Support up to 2 digits after the decimal point.
registrationDate Optional Number User registration date. 10 digit timestamp.
msgCount Optional Number Number of message sent
msgType Optional String Message type
pkgChannel Optional String Package channel
userIp Optional String User IP address
did Optional String User device ID
dtype Optional String User device type:1:iPhone 2:android 3: ipad 4:wphone 5: pc 6:web 7:wap
extra Optional map extra data, exp:“extra” : {“server”: “123”,“version”:“456”}
checkTags Optional array the type you want to filter
callbackUrl Optional String callback url(not recommend, config this at console)
callbackSecretKey Optional String callback secret key(not recommend, config this at console)
  • Example of request body:

    JSON Response
          {
          "content":“fuck you”,
          "userId":"1234556",
          "strategyId":"123"  //Not required, if it is empty, the default policy will be called.
            }     
    
  • Request signature:

When the user requests the Text Check API, the request can be signed with the appId and secretKey. When the API receives the request with the signature information, it will verify the signature using the same algorithm, and if the signature is found to be inconsistent, the API will return 401 error to the user.

If the API validation signature is consistent and the user corresponding to the appId has permission to operate the requested resource, the request succeeds, otherwise the API returns 401 error.

  • Request Header to send a signature via HTTP

Method: Add a header named Authorization in the request, whose value is the signature value. For example:

 Authorization: ****
  • Signature calculation method
  1. Canonicalized Query String:

Convert the request body JSON string to a hexadecimal string (not Base64) by doing sha256 encoding with UTF-8 character encoding.

CanonicalizedQueryString = hex(sha256(jsonBody))

  1. Constructs the signed string StringToSign ("\n" stands for ASCII newline character):

     StringToSign = HTTPMethod + "\n" +
                    HostHeaderInLowercase + "\n" +
                    HTTPRequestURI + "\n" +
                    CanonicalizedQueryString <get from previous> + "\n" +
                    "X-AppId:" + SAME_APPID_IN_HEADER + "\n" +
                    "X-TimeStamp:" + SAME_TIMESTAMP_IN_HEADER
    

The HTTP RequestURI is the absolute path to the request URI, without the request string. If the HTTPRequestURI is empty, also keep a forward slash (/)

The hash-based message authentication code (HMAC) is created using the HMAC-SHA256 protocol and the signature is calculated.

  1. StringToSign as the signature string, secretKey as the secret key and SHA256 as the hash algorithm.

    For more information about HMAC, see: https://tools.ietf.org/html/rfc2104.
    
  2. Converting the results of the previous step to a BASE64 string

  3. Put the BASE64 string into the Authorization of HTTP request Header

  • Example of signature

Below is an example of appId & secretKey & video.

appId=***
secrectKey=****
content="fuck you"
userId=1235678

Below is an example of request type.

{
 "content":"fuck you",
 "userId": "12345678"
}

Generate CanonicalizedQueryString

b3ad8e9d16439ccd5e91924d2516bf9592975003f69beff44e56cddf47bd3118

Generate StringToSign

  POST
  tsafe.ilivedata.com
  /api/v1/text/check
  b3ad8e9d16439ccd5e91924d2516bf9592975003f69beff44e56cddf47bd3118
  X-AppId:****
  X-TimeStamp:2020-07-31T07:59:03Z

Signatures from HMAC calculations

*****

HTTP Response

Content-Type: application/json;charset=UTF-8

The result is in JSON format, please refer to the following example.

  • Example of HTTP response:

Description of returning json field:

Field name Type Description
errorCode Number Error code: 0 means success
errorMessage String Error message
textSpam json object Resut message
warning Boolean Customize the alarm information of advertising words, and configure it when adding a blacklist on the console
taskId String Unique identifier to distinguish different calls
startTime Number Timestamp, representing the detection text call time
endTime Number Timestamp, representing the return time of the detected text result

textSpam:

Field name Type Description
content String After the detection is complete, sensitive words will change to asterisks if they contain sensitive words, and other content will be returned normally.
result Number 0: Pass, 1: Recommended for review, 2: Fail
tages json array Classified information
wordList json array List of sensitive words

tags:

Field name Type Description
tag Number Classified information:
100: politics, 110: violence, 120: prohibited, 130: eroticism, 150: advertisement, 160: insults, 170: Hate speech, 180: Minor protection, 190: sensitive hot spots,410:Irregular Emoticons, 420:Nickname,300:advertising law,220:private transaction,900: other, 999: customization
tagName String Detect first-level type names for text hits
tagNameEn String Detect first-level type names for text hits(English)
level Number Classification level,0:Normal,1:Suspected,2:Abnormal
confidence Number confidence,between 0 and 100,oney when tag=150,confidence is not null; The higher the value, the more likely to be an advertisement
subTags json object Secondary classification of sensitive information

subTags:

Field name Type Describe
subTag Number Secondary classification information reference Classification Code
subTagName String Detect secondary type names for text hits
subTagNameEn String Detect secondary type names for text hits(English)
wordList array of strings hit details
  • Response example :

    JSON response

          {
         "errorCode": 0,
         "textSpam": {
             "content": "****",
             "result": 2,
             "tags": [
                 {
                     "tag": 160,
                     "level": 2,
                     "tagName": "辱骂",
                     "tagNameEn": "insults",
                     "subTags": [
                         {
                             "subTag": 160001,
                             "subTagName": "谩骂人身攻击",
                             "subTagNameEn": "insults and personal attacks",
                             "wordList": [
                                 "fuck"
                             ]
                         }
                     ]
                 }
             ],
             "wordList": [
                 "fuck"
             ]
          },
          "taskId": "c01b212f-3e31-4a2e-8346-b6f6ce3a3456",
          "startTime": 1660103900367,
          "endTime": 1660103900374
      }
    

Error Code

HTTP Status Code Error code Error message Cause of error
200 0 This field will be ommitted
429 1104 Out of Rate Limit Frequency of requests exceeds the limit
405 1004 Method Not Allowed The http request method can only be get or post. If it is post, header must have content-type,and its value should be application/x-www-form-urlencoded
400 1002 API Not Found The corresponding API was not found according to the path of the http request.
400 1003 Bad Request Parsing request failed
400 2000 Missing Parameter Missing parameters content
400 2102 Input Too Long The length of the parameter content exceeds the limit.
401 1102 Unauthorized Client Parameter appId invalid
401 1106 Missing Access Token Missing Authorization
401 1107 Invalid Token Incorrect Authorization
401 1108 Expired Token Expired timeStamp
401 2000 Missing Parameter Missing timeStamp
401 2001 Invalid Parameter TimeStamp format error