I got this fatal error while using twilio voice - php

PHP Fatal error: Uncaught exception 'Twilio\Exceptions\RestException' with message '[HTTP 400] Unable to create record: Account not authorized to call +126878****. Perhaps you need to enable some international permissions: https://www.twilio.com/user/account/settings/international' in /home/gwalioro/public_html/swifnix.com/works/call/twilio-php-master/Twilio/Version.php:85
Code Here
require __DIR__ . '/twilio-php-master/Twilio/autoload.php';
use Twilio\Rest\Client;
// Your Account SID and Auth Token from twilio.com/console
$account_sid = 'ACf9bd660b13b0******';
$auth_token = '7e5d0992f716420dad9******';
// In production, these should be environment variables. E.g.:
// $auth_token = $_ENV["TWILIO_ACCOUNT_SID"]
// A Twilio number you own with SMS capabilities
$twilio_number = "+12015****";
// Where to make a voice call (your cell phone?)
$to_number = "+1268784****";
$client = new Client($account_sid, $auth_token);
$call = $client->account->calls->create(
$to_number,
$twilio_number,
array(
"url" => "http://demo.twilio.com/docs/voice.xml"
)
);
echo $call->sid;

I believe, the Error speaks for itself :)
You need to enable International Permissions. This is made for you not to pay more, in case you don't need that.
This is what Twilio manual tells us:
Need to make outbound calls outside of the U.S, and want to select the regions and countries you’ll allow to protect your project from high-cost routes and potential fraud?
see more in Twilio docs

Twilio developer evangelist here.
Your Twilio account does not have permission to call the country you are trying to call. You can fix this though. The link in the error ends up taking you to international SMS permissions, so you need to allow the country you are trying to call by logging into your Twilio account and visiting this page: https://www.twilio.com/console/voice/calls/geo-permissions

Related

make and receive call betwen browser and phone to discuss like a simple call

<?php
// Include the bundled autoload from the Twilio PHP Helper Library
require __DIR__ . '/vendor/autoload.php';
use Twilio\Rest\Client;
// Your Account SID and Auth Token from twilio.com/console
$account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$auth_token = '8XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
// In production, these should be environment variables. E.g.:
// $auth_token = $_ENV["TWILIO_ACCOUNT_SID"]
// A Twilio number you own with Voice capabilities
$twilio_number = "+12244073476";
// Where to make a voice call (your cell phone?)
$to_number = '+22678733599';
$client = new Client($account_sid, $auth_token);
try {
$client->account->calls->create(
$to_number,
$twilio_number,
array(
// two url can't function because the first url will be erase by the value of the second
"url" => "http://demo.twilio.com/docs/voice.xml"
)
);
// echo "Started call : " . $client->sid;
} catch (Exception $e) {
echo "Error : " . $e->getMessage();
}
?>
When I start the call to the phone number from twilio number, it's okay. But it is impossible to make communication.
How can I make communication after answering the call?
Twilio developer evangelist here.
Your title says you want to connect a browser to a phone. However, your code only shows use of the REST API.
To create calls from a browser to a phone you need to use the Twilio Voice SDK. I would recommend that you go through the instructions to run the Voice SDK quick start application. That will explain how making a call from a browser to a phone works and give you an example application to run and investigate. The quick start application is fully documented.

Twilio PHP fatal error

So I've been testing out twilio on a free web hosting server and this is what I get:
Fatal error: Class 'Twilio\Rest\Api' not found in /home/u512189195/public_html/twilio-php-master/Twilio/Rest/Client.php on line 263
This is my code:
<?php
// Require the bundled autoload file - the path may need to change
// based on where you downloaded and unzipped the SDK
require __DIR__ . '/twilio-php-master/Twilio/autoload.php';
// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;
// Your Account SID and Auth Token from twilio.com/console
$sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$token = 'your_auth_token';
$client = new Client($sid, $token);
// Use the client to do fun stuff like send text messages!
$client->messages->create(
// the number you'd like to send the message to
'+15558675309',
array(
// A Twilio phone number you purchased at twilio.com/console
'from' => '+15017250604',
// the body of the text message you'd like to send
'body' => "Hey Jenny! Good luck on the bar exam!"
)
);
?>
I've also tried without the __DIR__ .
Obviously, I've replaced the variables with my own data.
I've uploaded the php master library which we get from twilio documentation website. - https://www.twilio.com/docs/libraries/php
You can install twilio package via composer
https://packagist.org/packages/twilio/sdk
then;
<?php
require __DIR__ . '/vendor/autoload.php';
...
use Twilio\Rest\Client;
...
You should check that the class exists in the library you downloaded.
Look for:
twilio-php-master/Twilio/Rest/Api.php
If it is missing (and that is what the error message you get implies) then you need to download a more current version of the helper library.
See the section on 'Using without Composer' here.

Connecting to Twilio API using PHP

The example code asks for a $sid and $token.
I logged in to my account and went to Dev Tools → API Keys and created a new key which generated a Sid and Secret.
I went back to Account Settings → API Credentials and I have a AccountSID and AuthToken but the AccountSID is not the same as the Sid shown at Dev Tools → API Keys.
So I have 4 different strings, what am I suppose to do with them? What is the $sid that the example code asks for, is it the Sid in Dev Tools - API Keys or the AccountSID in Account Settings → API Credentials, and what on earth is the $token, I don't see this anywhere?
I've tried using a mixture on the below example code, with PHP error logging enabled, but it just causes the page to load as Server Error 500.
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/twilio-php-master/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "";
$token = "";
$client = new Services_Twilio($sid, $token);
// Loop over the list of numbers and echo a property for each one
foreach ($client->account->incoming_phone_numbers as $number) {
echo "<select>" . $number->phone_number . "</select>";
}
Side note: Does Twilio charge for API calls (actual API usage, not purchasing etc.)?
Twilio developer evangelist here.
I can see how that got confusing. For what you're trying to do, you can just grab the AccountSid and AuthToken from your dashboard. Once you're there, just expand "Show API Credentials" and copy the values.
As for your question, Twilio will not charge for requests like the one you're trying to make. Worth having a look at our billing and pricing FAQ to get some more information.
Hope this helps you

AdSense Management API - Missing required parameter: redirect_uri With Service Account

I am getting the following Error when trying to connect with the AdSense Management API Example:
Missing required parameter: redirect_uri
I am using a service Account, because my Server handles all the interaction between the adSense api. The user is not involved. Here is my PHP Code:
$client = new Google_Client();
$client->setApplicationName("PeopleHelpingPeople"); // name of your app
// set assertion credentials
$client->setAssertionCredentials(
new Google_Auth_AssertionCredentials(
"...",
array('https://www.googleapis.com/auth/analytics.readonly'),
file_get_contents('client_data.json') // keyfile you downloaded
));
$client->setScopes(array(
'https://www.googleapis.com/auth/analytics.readonly'
));
$client->setClientId("..."); // from API console
$client->setAccessType('offline_access'); // this may be unnecessary?
// Create service.
$service = new Google_Service_AdSense($client);
Why am I getting this Error?
If you are trying to use a ServiceAccount from the developers console, the kind of account that gives you a p12 file, those will not work with Adsense.
Take a look at the note on this page https://developers.google.com/adsense/management/getting_started
$client->setRedirectUri() may get you past this error but it wont solve your ultimate issue

Is there anyway to send a text message from Twilio so that the from number contains an extension?

Is there anyway to send a text message from Twilio so that the from number contains an extension?
Something like this:
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('twilio-php/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "...";
$token = "...";
$client = new Services_Twilio($sid, $token);
$client->account->messages->sendMessage(
"+441337944066+123#", // From
"+441234567891", // To
"Hello world" // Body
);
At the moment attempting this produces this error message:
Fatal error: Uncaught exception 'Services_Twilio_RestException' with message 'The 'From' number +441337944066+123# is not a valid phone number or shortcode.'
Twilio Support here.
Unfortunately we do not support extensions when sending messages.
However if you're looking to dial an extension on voice calls you can use the SendDigits parameter:
https://www.twilio.com/docs/api/rest/making-calls
Tom
It was my understanding that you needed to send messages with a FROM value being a valid Twillio number. Since the wrapper/helper is using the REST API it should still be bound by those restrictions. See documentation about that here: http://www.twilio.com/docs/api/rest/sending-messages
So, unless you purchased the number from Twillio and it has an extension, unfortunately, I don't believe that is possible.

Categories