Updated on 2025-11-13 GMT+08:00

Calling Back Data on Twitter

Function

Messages are pushed to Twitter when creating the Twitter channel. This interface is called back on Twitter for authentication.

Usage Description

  • Prerequisites

    The Twitter channel has been correctly created in the AICC, and the callback URL entered on the Twitter developer platform is correct.

    For details, see the official document at https://developer.twitter.com/en/docs/twitter-api.

Interface Authentication

  /**
     * Logic of channel authentication
     *
     * @param request Request
     * @param response Response
     */
    @Override
    public void confirm(HttpServletRequest request, HttpServletResponse response) {
        JSONObject returnObj = new JSONObject();
        String requestUrl = UsUriUtils.getRequestURI(request);
        String channelId = requestUrl.substring(requestUrl.lastIndexOf("/") + 1);
        AiccLog.intf("start deal with twitter confirm url,channelId:{}", channelId);
        if (CommonUtil.isEmpty(channelId)) {
            log.error("The channelId is null when check confirm url");
            return;
        }
        String crcToken = request.getParameter("crc_token");
        ChannelConfig channelConfig = adapterCommonService.getChannelConfig(channelId);
        String consumerSecret = twitterRedisService.getConsumerSecretAndDelete(channelId, channelConfig.getTenantId());
        if (StringUtils.isEmpty(consumerSecret)) {
            consumerSecret = getConsumerSecretFromChat(channelId);
        }
        if (StringUtils.isEmpty(consumerSecret)) {
            log.error("channel id : {} consumer parameter lost!", channelId);
        }
        try {
            String responseCode = BaseUtil.hMacSha256(crcToken, consumerSecret);
            returnObj.put("response_token", "sha256=" + responseCode);
        } catch (NoSuchAlgorithmException | InvalidKeyException e) {
            log.error("hmac sha256 error,channelId:{},tenantId:{}", channelId,channelConfig.getTenantId());
        }
        AiccLog.intf("end deal with twitter confirm url,channelId:{}", channelId);
    }

Interface Prototype

Table 1 Interface prototype description

Method

GET

URL

https://{IP address}:{Port number}/social/on/twitter/{channelId}

{IP address}:{Port number} indicates the IP address and port number of the NSLB exposed externally.

{channelId} indicates the channel ID.

Request Parameters

Table 2 Request header parameter

Parameter

Mandatory or Not

Type

Default Value

Description

Content-Type

Yes

String

None

The value is fixed at application/x-www-form-urlencoded.

Table 3 Request parameter

Parameter

Mandatory or Not

Type

Default Value

Description

crc_token

Yes

String

None

Used to generate an MO interface authentication token.

Response Parameters

Table 4 Response parameter

Parameter

Mandatory or Not

Type

Default Value

Description

response_token

Yes

JSON object

None

Used to generate an MO interface authentication token.

Example

  • Request
    GET
    Content-Type: application/json;charset=UTF-8
    https://ip/social/on/twitter/{channelId}
    x-www-form-urlencoded: key 
    crc_token:xxxxxxxxxxxxxxxxxx
  • Response
    HTTP/1.1 200 OK
    Content-Type: application/json;charset=UTF-8
    {
    "response_token": "sha256=xxxxxxxxxx"
    }