[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 [](http://travis-ci.org/twilio/twilio-php) 2 3 ## Installation 4 5 You can install **twilio-php** via PEAR or by downloading the source. 6 7 #### Via PEAR (>= 1.9.3): 8 9 PEAR is a package manager for PHP. Open a command line and use these PEAR 10 commands to download the helper library: 11 12 $ pear channel-discover twilio-pear.herokuapp.com/pear 13 $ pear install twilio/Services_Twilio 14 15 If you get the following message: 16 17 $ -bash: pear: command not found 18 19 you can install PEAR from their website, or download the source directly. 20 21 #### Via Composer: 22 23 **twilio-php** is available on Packagist as the 24 [`twilio/sdk`](http://packagist.org/packages/twilio/sdk) package. 25 26 #### Via ZIP file: 27 28 [Click here to download the source 29 (.zip)](https://github.com/twilio/twilio-php/zipball/master) which includes all 30 dependencies. 31 32 Once you download the library, move the twilio-php folder to your project 33 directory and then include the library file: 34 35 require '/path/to/twilio-php/Services/Twilio.php'; 36 37 and you're good to go! 38 39 ## A Brief Introduction 40 41 With the twilio-php library, we've simplified interaction with the 42 Twilio REST API. No need to manually create URLS or parse XML/JSON. 43 You now interact with resources directly. Follow the [Quickstart 44 Guide](http://readthedocs.org/docs/twilio-php/en/latest/#quickstart) 45 to get up and running right now. The [User 46 Guide](http://readthedocs.org/docs/twilio-php/en/latest/#user-guide) shows you 47 how to get the most out of **twilio-php**. 48 49 ## Quickstart 50 51 ### Send an SMS 52 53 ```php 54 <?php 55 // Install the library via PEAR or download the .zip file to your project folder. 56 // This line loads the library 57 require('/path/to/twilio-php/Services/Twilio.php'); 58 59 $sid = "ACXXXXXX"; // Your Account SID from www.twilio.com/user/account 60 $token = "YYYYYY"; // Your Auth Token from www.twilio.com/user/account 61 62 $client = new Services_Twilio($sid, $token); 63 $message = $client->account->messages->sendMessage( 64 '9991231234', // From a valid Twilio number 65 '8881231234', // Text this number 66 "Hello monkey!" 67 ); 68 69 print $message->sid; 70 ``` 71 72 ### Make a Call 73 74 ```php 75 <?php 76 // Install the library via PEAR or download the .zip file to your project folder. 77 // This line loads the library 78 require('/path/to/twilio-php/Services/Twilio.php'); 79 80 $sid = "ACXXXXXX"; // Your Account SID from www.twilio.com/user/account 81 $token = "YYYYYY"; // Your Auth Token from www.twilio.com/user/account 82 83 $client = new Services_Twilio($sid, $token); 84 $call = $client->account->calls->create( 85 '9991231234', // From a valid Twilio number 86 '8881231234', // Call this number 87 88 // Read TwiML at this URL when a call connects (hold music) 89 'http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient' 90 ); 91 ``` 92 93 ### Generating TwiML 94 95 To control phone calls, your application needs to output 96 [TwiML](http://www.twilio.com/docs/api/twiml/ "Twilio Markup Language"). Use 97 `Services_Twilio_Twiml` to easily create such responses. 98 99 ```php 100 <?php 101 require('/path/to/twilio-php/Services/Twilio.php'); 102 103 $response = new Services_Twilio_Twiml(); 104 $response->say('Hello'); 105 $response->play('https://api.twilio.com/cowbell.mp3', array("loop" => 5)); 106 print $response; 107 ``` 108 109 That will output XML that looks like this: 110 111 ```xml 112 <?xml version="1.0" encoding="utf-8"?> 113 <Response> 114 <Say>Hello</Say> 115 <Play loop="5">https://api.twilio.com/cowbell.mp3</Play> 116 <Response> 117 ``` 118 119 ## [Full Documentation](http://readthedocs.org/docs/twilio-php/en/latest/ "Twilio PHP Library Documentation") 120 121 The documentation for **twilio-php** is hosted 122 at Read the Docs. [Click here to read our full 123 documentation.](http://readthedocs.org/docs/twilio-php/en/latest/ "Twilio PHP 124 Library Documentation") 125 126 ## Prerequisites 127 128 * PHP >= 5.2.3 129 * The PHP JSON extension 130 131 ## Reporting Issues 132 133 We would love to hear your feedback. Report issues using the [Github 134 Issue Tracker](https://github.com/twilio/twilio-php/issues) or email 135 [[email protected]](mailto:[email protected]). 136
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |