我正试图在Wordpress中使用Twilio API发送短信,但我不明白什么是curl -u
。现在我想通过wp_remote_post使用twilio和wordpress发送短信。
见twilio发送短信文档API(通过JSON)
我的代码:
function sending_sms_via_twilio_api(){
$oauth_args = array(
"body" => array(
"Body" => "Hello World",
"To" => "0000000",
"From" => "5555555",
),
"my_Sid:my_token"
);
$response = wp_remote_post('https://api.twilio.com/2010-04-01/Accounts/AC28fcd041ffe3edb8029779894b7912d3/Messages.json', $oauth_args);
$result = json_decode( wp_remote_retrieve_body($response), true );
print_r($result);
}
结果是:
Array([code]=>20003[detail]=>您的AccountSid或AuthToken不准确的[message]=>身份验证错误-未提供凭据[更多信息]=>[状态]=>401)
有什么解决方案吗?
这是一个简单的身份验证问题。您应该再次检查您的凭据。
使用错误凭据对https://{AccountSid}:{AuthToken}@api.twilio.com/2010-04-01/Accounts
进行的GET
调用会出现此问题。
此外,api响应会向您提供以下错误页面作为建议:https://www.twilio.com/docs/errors/20003
希望它能帮助