1
votes

I am trying to send sms messages using Twilio API in Wordpress, but I don't understand what is curl -u. Now I want to send sms using twilio and wordpress via wp_remote_post.

See twilio send sms docs API (via JSON)

My code:

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);
}

Result is:

Array ( [code] => 20003 [detail] => Your AccountSid or AuthToken was incorrect. [message] => Authentication Error - No credentials provided [more_info] => [status] => 401 )

Any solutions?

1
is that your actual code? i think you need to find out what to put on "my_Sid:my_token" - Giulio Caccin
xxxxxxxxxxxxxxx:xxxxxxxxxxxxxx - Sultan
I have my token and my sid and i used it, but not working api! - Sultan

1 Answers

1
votes

That is a simple authentication problem. You should check your credentials again.

A GET call on https://{AccountSid}:{AuthToken}@api.twilio.com/2010-04-01/Accounts with wrong credentials give that problem.

Also the api response give this error page as advice for you: https://www.twilio.com/docs/errors/20003

Hope it helps