Difference between revisions of "PHP/Getting Started"

From SmartBots Developers Docs
Jump to: navigation, search
m (Gtaskincentral moved page HTTP API/PHP/Getting Started to PHP/Getting Started)
Line 43: Line 43:
 
</source>
 
</source>
  
[[HTTP_API/PHP|Prev Section (Introduction)]]<div class="floatright">[[HTTP_API/PHP/Performing_Actions|Next Section (Performing Actions)]]</div>
+
[[PHP|Prev Section (Introduction)]]<div class="floatright">[[PHP/Performing_Actions|Next Section (Performing Actions)]]</div>
 
{{NavMenu}}
 
{{NavMenu}}
 
__NOTOC__
 
__NOTOC__

Revision as of 08:11, 25 August 2016

Getting Started

Before following these instructions, please download the source files and place them into your project.

To begin, you will first need to create a blank .php file and include the 'smartbots_api.php' file.

<?php
    include("smartbots_api.php"); // Include the SmartBots API file.

Next, we will need to define your SmartBots Developer API key, your bot's name and access code so that it's easier to use them later.

$apiKey        = "e40e365171a99nl05bdmd697273b573t"; // SmartBots API Key.
$botName       = "Example Resident"; // The bot's full name.
$botAccessCode = "KbYpnfa"; // The bot's access code.

If you're not familiar with Object-Orientated PHP, the next section may look a little strange, however follow the instructions and all should be clear.

Now we will create the $bot variable and instansiate a new SmartBot() class so that we can begin making our bot function.

$bot = new SmartBot(); // Instansiate a new SmartBot class.

To let the SmartBots API know what bot we are going to be controlling, we now need to use the setup() method/function to enter in the variables we created earlier. The setup process returns TRUE or FALSE, depending on whether or not it was successful, meaning that you would use it within an 'if' statement if you wanted.

$bot->setup($apiKey, $botName, $botAccessCode); // Pass the setup variables to the API.

Your SmartBot is now connected to the API and is ready to accept some awesome functions! At the end of this section, your code could look a little something like this:

<?php
    include("smartbots_api.php"); // Include the SmartBots API file.

    $apiKey        = "e40e365171a99nl05bdmd697273b573t"; // SmartBots API Key.
    $botName       = "Example Resident"; // The bot's full name.
    $botAccessCode = "KbYpnfa"; // The bot's access code.

    $bot = new SmartBot(); // Instansiate a new SmartBot class.
    $bot->setup($apiKey, $botName, $botAccessCode); // Pass the setup variables to the API.
?>
Prev Section (Introduction)