skip to Main Content

There
I’m Using Twillio Example api

// Step 1: Get the Twilio-PHP library from twilio.com/docs/libraries/php, 
// and move it into the folder containing this sendnotifications.php file.
require "Services/Twilio.php";

// Step 2: set our AccountSid and AuthToken from https://twilio.com/console
$AccountSid = "ACea465f2e60ae87332cf47adb0e4aad64";
$AuthToken = "your_auth_token";

// Step 3: instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);

// Step 4: make an array of people we know, to send them a message. 
// Feel free to change/add your own phone number and name here.
$people = array(
    "+15558675309" => "Curious George",
    "+15558675308" => "Boots",
    "+15558675307" => "Virgil",
);

// Step 5: Loop over all our friends. $number is a phone number above, and 
// $name is the name next to it
foreach ($people as $number => $name) {

    $sms = $client->account->messages->sendMessage(

        // Step 6: Change the 'From' number below to be a valid Twilio number 
        // that you've purchased
        "+15017250604", 

        // the number we are sending to - Any phone number
        $number,

        // the sms body
        "Hey $name, Monkey Party at 6PM. Bring Bananas!"
    );

    // Display a confirmation message on the screen
    echo "Sent message to $name";
}

and here is my code

// Step 1: Get the Twilio-PHP library from twilio.com/docs/libraries/php, 
// and move it into the folder containing this sendnotifications.php file.
require "Services/Twilio.php";

// Step 2: set our AccountSid and AuthToken from https://twilio.com/console
$AccountSid = "accountsid";
$AuthToken = "authtoken";

// Step 3: instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);

// Step 4: make an array of people we know, to send them a message. 
// Feel free to change/add your own phone number and name here.
$people = array(
    "my-number-goes-here" => "Ali M. Ayad",

);

// Step 5: Loop over all our friends. $number is a phone number above, and 
// $name is the name next to it
foreach ($people as $number => $name) {

    $sms = $client->account->messages->sendMessage(

        // Step 6: Change the 'From' number below to be a valid Twilio number 
        // that you've purchased
        "+13862593325", 

        // the number we are sending to - Any phone number
        $number,

        // the sms body
        "Hey Ali This is test message form the api"
    );
    // Display a confirmation message on the screen
    echo "Sent message to $name";
}

when i put this code and i change the auth and id and the number is give my this message

Fatal error: Uncaught exception ‘Services_Twilio_RestException’ with message ‘Authentication Error – invalid username’ in C:AppServwwwtwServicesTwilio.php:297 Stack trace: #0 C:AppServwwwtwServicesTwilio.php(180): Base_Services_Twilio->_processResponse(Array) #1 C:AppServwwwtwServicesTwilioListResource.php(92): Base_Services_Twilio->createData(‘/2010-04-01/Acc…’, Array) #2 C:AppServwwwtwServicesTwilioRestMessages.php(24): Services_Twilio_ListResource->_create(Array) #3 C:AppServwwwtwServicesTwilioRestMessages.php(71): Services_Twilio_Rest_Messages->create(Array) #4 C:AppServwwwtwsendnotifications.php(48): Services_Twilio_Rest_Messages->sendMessage(‘+13862593325’, ‘+201063378955’, ‘Hey Ali This is…’) #5 {main} thrown in C:AppServwwwtwServicesTwilio.php on line 297
i’m using appserv

2

Answers


  1. As the error message says (almost) clearly:

    Authentication Error – invalid username

    Assuming you are already registered at twilio; make sure you correctly defined your username and token in the real code you use:

    • Re-check again and again your username (and AuthToken also) for possible encoding issues and/or mistakes involving:
      • Correctly matching character case,
      • Trailing spaces, and
      • Special characters.

    Also verify that your account is still valid at twilio.

    Login or Signup to reply.
  2. “Authentication Error – invalid username'”

    Your AccountSid and AuthToken are the “master keys” to your account. To authenticate using these “master keys,” use HTTP basic auth with the username set to your AccountSid and the password set to your AuthToken. Your AccountSid and AuthToken can be found on your Account Dashboard.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search