sábado, 8 de julio de 2017

Using with Composer

enabled frist curl
sudo apt-get install php-curl
Or if you're using the old PHP5
sudo apt-get install php5-curl
The recommended method for installing the SDK is via Composer. You can add the PHP SDK to your composer.jsonfile with the require command.
composer require twilio/sdk
If you are using a framework like Laravel, the Twilio SDK may be automatically loaded for you and ready to use in your application. If you're using Composer in an environment that doesn't handle autoloading, you can require the autoload file from the "vendor" directory created by Composer if you used the install command above. Here is a basic example of using the SDK to send a text message.
<?php
// Required if your environment does not handle autoloading
require __DIR__ . '/vendor/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!'
    )
);
?>

Using without Composer

While we recommend using a package manager to track the dependencies in your application, it is possible to download and use the PHP SDK manually. You can download the full source of the PHP SDK from GitHub, and browse the repo if you would like. To use the SDK in your application, unzip the SDK download file in the same directory as your PHP code. In your code, you can then require the autoload file bundled with the SDK.
<?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!"
    )
);

More Documentation

Once you're up and running with the PHP SDK, you'll find code samples supporting the latest version of the library in our REST API reference docs and in the docs for every Twilio product. In addition to the REST API reference, auto-generated PHP API documentation can be found here.

Troubleshooting

On Windows, you may receive an error "SSL certificate problem: self signed certificate in certificate chain". Please refer to the Twilio Help Center for instructions to fix.

Accessing the 4.x Version of the SDK

The most recent version of the PHP SDK is not API compatible with the previous 4.x version of the PHP SDK you may have used in previous Twilio applications. The older version will continue to work, and you will continue to find sample code for this version throughout our documentation. Should you need to install this version from Composer, you can do so with the following command.
composer require twilio/sdk:4.11.0
Alternately, you can view this version of the SDK on GitHub and download it directly from there.

Accessing Preview Twilio Features

Pre-release products are only available on the "alpha" release of the PHP SDK (version 5.x or higher). You can read more about the versioning strategy for the SDK here. Whenever a new version of the SDK is released, a corresponding "alpha" version will also be released and installable. For example, if the current production version of the SDK were "5.4.2", you could install the "alpha1" version with the following command.
composer require twilio/sdk:5.4.2-alpha1

Getting Help

We'd love to hear your feedback on the PHP SDK, and help you past any issues you may encounter. Feel free to drop us a line, and we'll make sure to get you sorted!

 Need some help?

No hay comentarios:

Publicar un comentario