Created
October 19, 2015 08:01
-
-
Save jokamjohn/79a5ebbf2ba467e0533c to your computer and use it in GitHub Desktop.
Code to subscribe a number on the AfricasTalking API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once "AfricasTalkingGateway.php"; | |
| //Specify your credentials | |
| $username = "myAfricasTalkingUsername"; | |
| $apiKey = "myAfricasTalkingAPIKey"; | |
| // Specify the number that you want to subscribe | |
| // Please ensure you include the country code (+254 for Kenya in this case) | |
| $phoneNumber = "+254711YYYZZZ"; | |
| //Specify your Africa's Talking short code and keyword | |
| $shortCode = "ABCDE"; | |
| $keyword = "myKeyword"; | |
| //Create an instance of our awesome gateway class and pass your credentials | |
| $gateway = new AfricasTalkingGateway($username, $apiKey); | |
| // Thats it, hit send and we'll take care of the rest. Any errors will | |
| // be captured in the Exception class as shown below | |
| try { | |
| $result = $gateway->createSubscription($phoneNumber, $shortCode, $keyword); | |
| //Only status Success signifies the subscription was successfully | |
| echo $result->status; | |
| echo $result->description; | |
| } | |
| catch(AfricasTalkingGatewayException $e){ | |
| echo $e->getMessage(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment