由于无效的CRC而导致注册推特网络钩子时遇到问题



我在注册我的推特网络钩子时遇到问题。 我正在使用 twitterdev/account-activity-dashboard,尽管请求到达了 webhook(我可以在日志中看到它(,但我不断得到这个回报:

网络钩子 URL 不符合要求。无效的 CRC 令牌或 json 响应格式。

我相信我已经非常仔细地遵循了这里的描述: https://github.com/twitterdev/account-activity-dashboard

我的凭据正确,权限正确,并且我已经设置了一个环境。

服务器端位于节点.js中。 此处提供了响应 webhook 创建请求的简单代码。

我正在使用加密库来创建 hmac(再次,如上面链接中提供的示例所示。

function twitterWebhook(req, res, next)
{
my.logger.verbose('Entered the Twitter Webhook');
my.logger.verbose('Here is the url: ' + JSON.stringify(req.url));
my.logger.verbose('Here is the query: ' + JSON.stringify(req.query));
var crc_token = req.query.crc_token;
my.logger.verbose('crc_token is:  ' + crc_token);
my.logger.verbose('secret is   :  ' + conf.T_consumer_secret);
var hmac = crypto.createHmac('sha256', 
conf.T_consumer_secret).update(crc_token).digest('base64');
my.logger.verbose('hmac is     :  ' + hmac);
if (req.method.toLowerCase() == 'get'){
var aResponse = {response_token:hmac};
var aResponseString = JSON.stringify(aResponse);
res.send(hmac);
}
response_token: 'sha256=' + hmac

您必须在响应令牌的开头添加sha256=,添加后修复了相同的问题。

我正在使用python3.7 + ngrok作为Twitter提供的callbakurl和nodejs服务来管理回调url,订阅。

  1. 在这里找到nodejs:官方Twitter帐户活动仪表板
  1. 这是我通过 ngrok 公开的烧瓶网络钩子

    @app.route('/webhook/twitter', methods=['GET'])
    def webhook_challenge():
    # creates HMAC SHA-256 hash from incoming token and your consumer secret
    sha256_hash_digest = hmac.new(API_KEY_SECRET.encode('utf-8'), msg=request.args.get('crc_token').encode('utf-8'),                                  digestmod=hashlib.sha256).digest()
    # construct response data with base64 encoded hash
    response = {'response_token': 'sha256=' + base64.b64encode(sha256_hash_digest).decode('utf-8')}
    # returns properly formatted json response
    return json.dumps(response)
    

请务必注意,在将应用设置为 Twitter 帐户 API 仪表板后,请继续并再次重新生成密钥。

由于您将运行两个应用程序,就我而言,它是 Flask 应用程序和 NodeJs 应用程序,请确保您更新所有应用程序中的所有消费 API 密钥和访问令牌。

未能更新任何内容将导致错误。就我而言,我没有更新 Flask 应用程序上的Consumer_Api_Secret,并且收到错误Webhook URL 不符合要求。无效的 CRC 令牌或 json 响应格式。

毕竟,管理您的订阅至关重要。

Twitter帐户仪表板(节点.js应用程序(坚持认为

记下已部署的 URL,重新访问"developer.twitter.com 应用设置"页面,并将以下 URL 值添加为列入白名单的回调 URL:

http(s)://your.app.domain/callbacks/addsub
http(s)://your.app.domain/callbacks/removesub
  1. http(s(可以是HTTP或HTTPS。

  2. 您的.app.domain可以是本地主机或 www.mysite.com

  3. 始终确保您的回调 url 在开头或结尾不包含任何空格。这一点我怎么强调都不为过。

相关内容

最新更新