I am new to twilio.I am using twilio trial account and I am using php.I have created my account and the verification code was sent to my number .But when i try to make a call i get the error
Error: The source phone number provided, +1937xxxxxx6, is not yet verified for your account. You may only make calls from phone numbers that you've verified or purchased from Twilio.
Here is my code
<?php
// Include the Twilio PHP library
require 'twilio-php-master/Services/Twilio.php';
// Twilio REST API version
$version = "2010-04-01";
// Set our Account SID and AuthToken
$sid = 'Axxxxxxxxxxxxxxxxxxffa58';
$token = 'f878xxxxxxxxxxxxxxxeb05';
// A phone number you have previously validated with Twilio
$phonenumber = '+19xxxxxxxx6';
// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($sid, $token, $version);
try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
'+91xxxxxxxx7', // The number of the phone receiving call
'http://demo.twilio.com/welcome/voice' // The URL Twilio will request when the call is answered
);
echo 'Started call: ' . $call->sid;
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
?>
It happened to me when using the test account/token.
I double checked that the my phone number is verified but it was giving me this error.
Then I replaced the test account with my real account sid/token and the call succeeds.
I consider this as a bug in their system.
tested with python 3.6, twilio 6.16.2
Related
Our code sends twilio sms messages by doing the following:
// send the text message to the member's mobile phone
try {
// attempt to send the message through Twilio
$tw_msg = $twilio_client->messages->create(
"+1".$recipient['address'],
array (
'From' => "+1".$org['twilio_number'],
'Body' => $txtmsg,
'StatusCallback' => CALLBACK_LINK.'/text_message_handler.php'
)
);
// else trap the error since the message could not be sent and the callback routine is not called
} catch (Exception $e) {
// process the text message error
process_text_msg_error($db, $e, $org, $msg, $recipient);
}
In the v4 library we would get the error code by doing the following:
// get the twilio error components
$twilio_error_status = $e->getStatus();
$twilio_error_code = $e->getCode();
$twilio_error_msg = $e->getMessage();
This is not giving us what we expected using the V5 library. How do we get the error status and code using the V5 lib?
Twilio developer evangelist here.
It looks to me like you need to update one of the methods you call on the exception to get the status code. The exception is now a RestException and has the method getStatusCode(). You should update to:
// get the twilio error components
$twilio_error_status = $e->getStatusCode();
$twilio_error_code = $e->getCode();
$twilio_error_msg = $e->getMessage();
Let me know if that helps at all.
I using twilio for call system, but my error:
Error: Account not authorized to call +84983xxxxxx. Perhaps you need
to enable some international permissions:
https://www.twilio.com/user/account/settings/international
I checked in Vietnam (+84) via https://www.twilio.com/user/account/settings/international but still encounter the same error
My php code:
<?php
require 'twilio-php/Services/Twilio.php';
function call_notify($number) {
// Twilio REST API version
$version = "2010-04-01";
// Set our Account SID and AuthToken
$sid = 'AC34962eb3f445dfa40893e64bb8xxxxxx';
$token = '9b0667c68299cf484228344d67xxxxxx';
// A phone number you have previously validated with Twilio
$phonenumber = '+155920xxxxx';
// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($sid, $token, $version);
try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
$number, // The number of the phone receiving call
'http://103.255.238.29/notify.xml' // The URL Twilio will request when the call is answered
);
echo 'Started call: ' . $call->sid;
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}
call_notify("+84983xxxxxx");
Please help me, thanks
Twilio developer evangelist here.
I clicked on the URL to the international settings but was redirected to the Messaging international settings.
Can you go to the Voice international settings here https://www.twilio.com/console/voice/settings/geo-permissions and ensure you have Vietnam checked on that page too.
I'll feedback that the error is pointing to the wrong page.
Let me know if that helps!
I am trying to list emails from a standard Gmail account (not a Google Apps account) using OAuth2 and a Service Account (actually, I want to send emails – but that can wait).
I have created the Project, created the service account, downloaded the private key, and enabled the Gmail API (and the Calendar API). I can successfully access my calendar using code very similar to the code below. However, I am receiving the following error when attempting to list mail messages.
Error refreshing the OAuth2 token, message: error_description "Unauthorized client or scope in request."
(For info. If I comment out the $credential->sub = … line, I get the following error: “(500) Backend Error” and I can see that this is logged in the Usage tab of the Developers API page).
Can anyone confirm that what I am trying to do is possible? And if so, any ideas where to go next?
Here is my code:
class mail
{
private $service;
public function __construct($clientid, $keyfile, $account_name, $app_name)
{
$client = new Google_Client();
$client->setApplicationName($app_name);
$this->service = new Google_Service_Gmail($client);
// Load the key in PKCS 12 format
$key = file_get_contents($keyfile);
$client->setClientId($clientid);
$credentials = new Google_Auth_AssertionCredentials(
$account_name, array('https://mail.google.com/'),$key);
$credentials->sub = 'myemailaddress...#gmail.com';
$client->setAssertionCredentials($credentials);
}
public function list_mail()
{
try
{
$result = $this->service->users_messages->listUsersMessages("me");
}
catch (Exception $e)
{
throw new Exception("Gmail API error: ".$e->getMessage()."<br />");
}
return $result;
}
}
$mail_obj = new mail(CLIENT_ID, KEY_FILE, SERVICE_ACCOUNT_NAME, APP_NAME);
$result = $mail_obj->list_mail();
I am using Twilio sdk to send SMS in my PHP based application,I have an array of phone numbers and sending an SMS to each number in this array in a loop.....the problem is while the loop is running if an invalid number comes twilio API returns 500 internal server error and it stops the loop without trying sending sms for rest of the numbers in the array.
This is the code I am using for sending sms :
public function sendSmsAction($userphones)
{
foreach($userphones as $user_phone)
{
$message = 'Thanks for coming';
$this->twiliosms($user_phone,$message);
}
}
private function twiliosms($phone_num,$message)
{
require Mage::getBaseDir()."/twilio-php-master/Services/Twilio.php";
$AccountSid = "XXXXXXX";
$AuthToken = "XXXXXXX";
$client = new Services_Twilio($AccountSid, $AuthToken);
try {
$message = $client->account->messages->create(array(
"From" => "+1XXXXXXXXXX",
"To" => $phone_num,
"Body" => $message,
));
} catch (Services_Twilio_RestException $e) {
echo $e->getMessage();
}
}
And this is the error I am getting :
Status: 500 Internal Server Error
The 'To' number +1XXXXXXXXXX is not a valid phone number or shortcode.
please help me out in handling this error.
Thanks in advance.
Finally, I got my solution....by just adding another catch() made it working fine...
catch(Exception $e)
{
}
I'm trying to access the status AFTER the call is done, and display it in the first page, not in the callback page.
i have calling page:
require 'twilio/Services/Twilio.php';
$sid = "xxx"; // Your Account SID from www.twilio.com/user/account
$token = "xxx"; // Your Auth Token from www.twilio.com/user/account
$client = new Services_Twilio($sid, $token);
try {
$call = $client->account->calls->create(
'000', // From a valid Twilio number
$number, // Call this number
// Read TwiML at this URL when a call connects (hold music)'
"http://myurl.com/voice.xml", array('Method' => 'GET','StatusCallback'=>'http://myurl.com/callback.php'));
if($call->status =='failed')result(array('status'=>'failed status '));
else result(array('status'=>$call->status));
} catch (Exception $e) {
result(array('status'=>'not a valid number'));
}
my issue is that i'm not understanding how i can get the $_POST info that twilio will send to my callback.php on my calling page.php....
Please read Twilio API explaintion Click here for reference from Twilio Site to know the post parameters from Twilio on your callback back page.
http://myurl.com/callback.php
$callDur = $_POST['CallDuration'];
$recdDur = $_POST['RecordingDuration'];
To get these values on other page store them in session and use them where you want.