简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM