twitter - 无法注册 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 得到了所有的要求:
- 已批准的开发者帐户。
- Account Activity 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_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 的可能解决方案。
谢谢
解决方案
您尝试从浏览器运行的代码将不起作用,因为 Twitter 不支持 CORS(这就是错误消息告诉您的内容)。curl 命令需要根据此答案使用表单数据进行 URL 提交
推荐阅读
- gcc - 在 gcc 中安装 icuin
- python-3.x - sep=' ' 不工作。是什么原因?
- javascript - 如何让 Cypress.$ 在 while 循环中获取选择器的最新值
- javascript - 在 PDFKit 中使用子数组访问子数组的 Javascript - NODE JS
- java - If else 程序
- excel - 从 Excel 表中填充的下拉列表未正确选择
- javascript - nodejs - 如何在注册后强制用户完成个人资料?
- python - 有没有办法在熊猫数据框中识别行实际包含数据的列
- ios - 应用程序在调用自定义按钮的 setNeedsDisplay 时崩溃
- rust - 了解枚举 Rust 的移动语义