首页 > 解决方案 > 无法注册 twitter webhook。{“错误”:[{“代码”:32,“消息”:“无法验证您。”}]}

问题描述

我正在尝试为 twitter webhook 注册一个端点,但它返回 {“errors”:[{“code”:32,“message”:“Could not authenticate you.”}]}

我正在使用twitter 示例请求来注册 webhook。这是我的 curl 请求, 注册 url的 curl 请求

curl --request POST --url "https://api.twitter.com/1.1/account_activity/all/:ENV_NAME/webhooks.json?https%3A%2F%2Fd216d0d30d8f.ngrok.io%2Fapi%2F1.0%2Fwebhooks%2Ftwitter" --header "authorization: OAuth oauth_consumer_key="CONSUMER_KEY", oauth_nonce="EhOhXekPMpf", oauth_signature="GvOx3V91BrfWuBuPKUuftYgRgHY%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1597823037", oauth_token="ACCESS_TOKEN", oauth_version="1.0""

我的端点在 https 上运行,使用 ngrok 隧道 端点在 https 上运行,使用 ngrok

我从 twitter 得到了所有的要求:

我尝试过使用 angular 和 https mydomain 请求。

//function to register twitter webhook 
registerTwitterWebhook() {

    // authorization in headers
    const headers = new HttpHeaders({
      'authorization': 'OAuth oauth_consumer_key="CONSUMER_KEY",oauth_nonce="UAkSZPWDfmM",oauth_signature="%2FWSSbq4R1eTbGF4X9xg1T1e9sY4%3D",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1597728768",oauth_token="ACCESS_TOKEN",oauth_version="1.0"',
      'Content-Type':  'application/x-www-form-urlencoded'
       })
    const url = 'https://api.twitter.com/1.1/account_activity/all/:ENV_NAME/webhooks.json?url="https%3A%2F%mydomain.com%2Fapi%2F1.0%2Fwebhooks%2Ftwitter"';
    return this.http.post(url, {}, { headers: headers });
}

在发送 POST 请求时,它显示如下 错误 Error chrome web console

请指导我注册 twitter webhook 的可能解决方案。

谢谢

标签: twitterwebhookstwitter-oauthtwitter4j

解决方案


您尝试从浏览器运行的代码将不起作用,因为 Twitter 不支持 CORS(这就是错误消息告诉您的内容)。curl 命令需要根据此答案使用表单数据进行 URL 提交


推荐阅读