Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use the new Twilio PHP API version (twilio-php-5.0.0-RC7)? #323

Closed
ghost opened this issue Jul 11, 2016 · 2 comments
Closed

How do I use the new Twilio PHP API version (twilio-php-5.0.0-RC7)? #323

ghost opened this issue Jul 11, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 11, 2016

Please can someone explain to me how I can convert this code to work with the new Twilio PHP API version available to download on GitHub (twilio-php-5.0.0-RC7)?

<?php
    // Get the PHP helper library from twilio.com/docs/php/install
    require_once('twilio/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);

    $messages = $client->account->messages->getIterator(0, 50, array(
        'To' => $_SERVER['QUERY_STRING']
    ));

    foreach ($messages as $message) {
        echo "<tr><td class=\"text-center\">" . $message->from . "</td><td class=\"text-center\">" . $message->date_sent . "</td><td class=\"text-center\">" . $message->body . "</td></tr>";
    }
    ?>

There is no longer a twilio/Services/Twilio.php file to include and I can't see anything of a similar name and also the documentation doesn't seem to have been updated with a similar example to the above as far as I can see.

I'm not using Composer

@mcelicalderon
Copy link

@alex-jch I'm not sure if there's is a way to use this library without composer, but I think there isn't. Please use composer. A new set of v5.x snippets is coming along and you will be able to see it in the API docs in the next few days incrementally. Take a look here. You can also get more information on how to use the new version here.

This is how your snippet would look in v5.x:

<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use \Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$messages = $client->account->messages->read(
    array("to" => $_SERVER['QUERY_STRING']),
    50
);
// Loop over the list of calls and echo a property for each one
foreach($messages as $message) {
    echo "<tr><td class=\"text-center\">" . $message->from . "</td><td class=\"text-center\">" . $message->dateSent->format('Y-m-d H:i:s') . "</td><td class=\"text-center\">" . $message->body . "</td></tr>";
}

@ihumanable
Copy link
Contributor

It is strongly suggested that you use composer, but you don't have to, the library ships with an autoloader that should allow you to use it standalone.

  1. Download the zip
  2. Take the Twilio folder and drop it into your project
  3. Add this line before using any Twilio classes
require_once 'Twilio/autoload.php';

use Twilio\Rest\Client;

$client = new Client(ACCOUNT_SID, AUTH_TOKEN); // assuming these constants exist

// Do cool stuff with the client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants