【问题标题】:API - Your AccountSid or AuthToken was incorrectAPI - 您的 AccountSid 或 AuthToken 不正确
【发布时间】:2021-06-18 02:05:41
【问题描述】:

我正在尝试在 Windows 10 中使用 Twilio API 发送 SMS 消息。我在 CMD 中输入以下请求:

curl "https://api.twilio.com/2010-04-01/Accounts/ACAccount SID/Messages.json" -X POST \
--data-urlencode "To=+Phone number" \
--data-urlencode "From=+Phone number" \
--data-urlencode "Body=Ahoy" \
-u Account SID:Auth Token

而我遇到:

{"code": 20003, "detail": "Your AccountSid or AuthToken was incorrect.", "message": "Authentication Error - No credentials provided", "more_info": "https://www.twilio.com/docs/errors/20003", "status": 401}curl: (6) Could not resolve host: \

我从提供的 url 中查找了错误消息,但我无法获得太多信息。我验证了 Auth 令牌和 SID 是正确的。如果这有所作为,我正在使用 Twilio 免费试用帐户。我已经放弃了故障排除。任何建议将不胜感激。

【问题讨论】:

  • 错误消息显示curl: (6) Could not resolve host: \ ,表示反斜杠被解释为 URL。您说您在命令提示符下使用的是 Windows 10?反斜杠 \ 在 Linux 中的 Bash 中用于将长命令拆分为多行。如果您使用的是 Windows,则需要将 \ 替换为 ^,请参阅此 SO question
  • @yvesonline 做到了!非常感谢!
  • 好东西,我会添加它作为答案然后你可以accept and vote就可以了。

标签: api curl twilio auth-token


【解决方案1】:

尝试使用API Explorer,消息 -> Create a Message。看看这是否有效,如果有效,请单击 Show your Auth Token 按钮并将其使用的 cURL 结构与您正在使用的结构进行比较。

此外,尽管您的示例代码看起来很干净,但出现此问题的另一种常见方式是智能引号潜入,例如当您从 Slack 复制非代码块格式的代码示例时。

【讨论】:

  • 我按照您的步骤操作,它产生了相同的 POST 请求。我确保 Auth Token 和 Account SID 的值与我上面的帖子相匹配。我可以在 twilio 中发送请求,但不能在 CMD 中发送。我确保将“C:\Windows\System32\curl.exe”添加到环境变量中的路径变量中,在我的工作站中。
【解决方案2】:

错误消息显示curl: (6) Could not resolve host: \,表示反斜杠被解释为 URL。

您说您在命令提示符中使用的是 Windows 10,反斜杠 \ 在 Linux 中的 Bash 中用于将长命令拆分为多行。如果您使用的是 Windows,则需要将 \ 替换为 ^,请参阅此 SO question

所以这应该在命令提示符下的 Windows 10 下工作:

curl "https://api.twilio.com/2010-04-01/Accounts/ACAccount SID/Messages.json" -X POST ^
  --data-urlencode "To=+Phone number" ^
  --data-urlencode "From=+Phone number" ^
  --data-urlencode "Body=Ahoy" ^
  -u Account SID:Auth Token

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-10
    • 2018-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多