【发布时间】: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 脚本,我会收到很好的响应。
有人知道发生了什么,我该如何解决?
谢谢!
【问题讨论】: