无法注册twitter webhook {“错误”:[{“代码”:32,”消息”:“无法验证您的身份”}}}

问题描述

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

我正在使用twitter sample request注册Webhook。这是我的卷曲要求, curl request to register url

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""

我的端点正在使用ngrok隧道在https上运行 endpoint running on https using ngrok

我已经收到了Twitter的所有要求:

  • 批准的开发者帐户。
  • 帐户活动API上的环境设置。
  • 有效的消费者密钥和机密。
  • 有效访问令牌和令牌密钥。

我尝试使用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_timestamp="1597728768",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的可能解决方案。

谢谢

解决方法

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

提交URL

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...