【问题标题】:“Non-200 response code during CRC GET request”“CRC GET 请求期间的非 200 响应代码”
【发布时间】:2021-04-29 17:54:36
【问题描述】:

我想注册一个 webhook。我的 webhook 端点 URL 中有这个 PHP 代码:

<?php
// Example app consumer secret found in apps.twitter.com
const APP_CONSUMER_SECRET = 'xxx';
// Example token provided by incoming GET request
$token = $_GET['crc_token'];
/**
 * Creates a HMAC SHA-256 hash created from the app TOKEN and
 * your app Consumer Secret.
 * @param  token  the token provided by the incoming GET request
 * @return string
 */

function get_challenge_response($token) {
  $hash = hash_hmac('sha256', $token, APP_CONSUMER_SECRET, true);
  $response = array(
    'response_token' => 'sha256=' . base64_encode($hash)
  );
  return json_encode($response);
}
// prints result
echo get_challenge_response($token);

如果我直接尝试(即使用浏览器本身),我会得到以下响应: {"response_token":"sha256=VvHK6oEH4CHfnP9ImMmidtjTHGy48DuACxR6TSYyCcQ="}

这让我觉得它可以正常工作,我还收到了 200 状态码。但是当我尝试调用 Twitter API 来注册 webhook 时,我总是会收到以下错误消息:

{
  "errors": [
    {
      "code": 214,
      "message": "Non-200 response code during CRC GET request (i.e. 404, 500, etc)."
    }
  ]
}

无论我尝试使用 Insomnia、Postman 还是 Account Activity Dashboard。这是没有意义的,因为如果我打开浏览器并打开我的 PHP 脚本,我会收到很好的响应。

有人知道发生了什么,我该如何解决?

谢谢!

【问题讨论】:

    标签: php http twitter webhooks


    【解决方案1】:

    Twitter 表示您的脚本返回的不是 HTTP 200 响应代码。这可能表明在 Twitter 请求期间发生了错误。

    1. 确保 webhook URL 正确。
    2. 记录来自 Twitter 的请求并确保您获得了预期的输入。
    3. 检查您的日志是否有错误。
    4. 尝试强制响应代码:
    http_response_code(200);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-16
      • 1970-01-01
      • 2016-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-02
      • 1970-01-01
      相关资源
      最近更新 更多