【问题标题】:Twillio Php apiTwilio Php api
【发布时间】:2017-08-09 00:59:55
【问题描述】:

那里 我正在使用 Twillio 示例 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";
}

这是我的代码

// 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";
}

当我输入此代码并更改身份验证和 id 时,数字是给我的此消息

致命错误:在 C:\AppServ\www\tw\Services\Twilio.php:297 中未捕获的异常“Services_Twilio_RestException”和消息“身份验证错误 - 无效用户名” 堆栈跟踪:#0 C:\AppServ\www\tw \Services\Twilio.php(180): Base_Services_Twilio->_processResponse(Array) #1 C:\AppServ\www\tw\Services\Twilio\ListResource.php(92): Base_Services_Twilio->createData('/2010-04- 01/Acc...', Array) #2 C:\AppServ\www\tw\Services\Twilio\Rest\Messages.php(24): Services_Twilio_ListResource->_create(Array) #3 C:\AppServ\www\ tw\Services\Twilio\Rest\Messages.php(71): Services_Twilio_Rest_Messages->create(Array) #4 C:\AppServ\www\tw\sendnotifications.php(48): Services_Twilio_Rest_Messages->sendMessage('+13862593325', '+201063378955', 'Hey Ali This is...') #5 {main} 在第 297 行的 C:\AppServ\www\tw\Services\Twilio.php 中抛出 我正在使用 appserv

【问题讨论】:

  • 非常直接的错误。您是否将您的AuthTokenAccoundSid 放入您可以从您的仪表板获得的?

标签: php twilio


【解决方案1】:

正如错误消息(几乎)清楚地表明:

身份验证错误 - 用户名无效

假设您已经在 twilio 注册;确保您在您使用的真实代码中正确定义了您的用户名和令牌:

  • 反复检查您的用户名(以及AuthToken)是否存在可能的编码问题和/或错误,包括:
    • 正确匹配字符大小写,
    • 尾随空格和
    • 特殊字符。

还要验证您的帐户在 twilio 上是否仍然有效。

【讨论】:

    【解决方案2】:

    “身份验证错误 - 用户名无效”

    您的 AccountSid 和 AuthToken 是您帐户的“主密钥”。要使用这些“主密钥”进行身份验证,请使用 HTTP 基本身份验证,用户名设置为您的 AccountSid,密码设置为您的 AuthToken。您的 AccountSid 和 AuthToken 可以在您的 Account Dashboard 上找到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-17
      • 1970-01-01
      • 1970-01-01
      • 2017-07-01
      • 2018-09-27
      相关资源
      最近更新 更多