【发布时间】:2015-09-14 10:46:55
【问题描述】:
我正在尝试在 Wordpress 中使用 Twilio API 发送短信,但我不明白 curl -u 是什么。现在我想通过wp_remote_post使用twilio和wordpress发送短信。
见twilio send sms docs API (via 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 是 不正确。 [消息] => 身份验证错误 - 未提供凭据 [更多信息] => [状态] => 401)
有什么解决办法吗?
【问题讨论】:
-
那是您的实际代码吗?我想你需要知道要穿什么
"my_Sid:my_token" -
xxxxxxxxxxxxxxx:xxxxxxxxxxxxxx
-
我有我的令牌和我的 sid 并且我使用了它,但没有工作 api!