Getting Started with Wildlink PHP Library
Requirements
- PHP 5.3+
- Composer
- Wildlink API credentials (App ID and Secret, if you need credentials, contact support@wildlink.me)
Step 1: Installation
Let’s first create a new project folder. You can do this however, you like, but we’ll prefer the command line for this example:
cd ~; mkdir example_wildlink_project; cd example_wildlink_project
Next, we need to install the Wildlink PHP library. The recommended way to install the library is with Composer. Composer is a dependency manager for PHP that automates much of the installation process. If you don’t already have Composer installed, you can install it for Mac/Linux via your command line (for Windows install, see Composer’s Installation Instructions).
curl -sS https://getcomposer.org/installer | php
With Composer installed, you can add the Wildlink PHP library via the command line:
php composer.phar require wildlink/wildlink-api-php
Step 2: Connecting to the Wildlink web service
Now that we have the Wildlink PHP library installed, let’s create a trivial project that connects to the Wildlink service and generates a wild.link “Vanity URL.” We call the very short URLs that users share “Vanity URLs” because we think they’re short and pretty (and much nicer to share than big long URLs).
First, let’s create a new file in our project directory.
touch index.php
Now, using your favorite editor, let’s open that file and add the following code:
<?php // autoload makes all our dependencies from composer available to this page require 'vendor/autoload.php'; use WildlinkApi\WildlinkClient; $app_id = 'YOUR_APP_ID_HERE'; // <-- replace this value $secret = 'YOUR_APP_SECRET_HERE'; // <-- replace this value // connect to the Wildlink service, this will generate and store a UUID $wf_client = new WildlinkClient($app_id, $secret); // you can now access the Device Key like this echo "Device Key is $wf_client->device_key<hr/>"; echo "Device ID is $wf_client->device_id<hr/>"; echo "Device Token is $wf_client->device_token<hr/>"; // IMPORTANT!! Store this $wf_client->device_key and $wfClient->device_id in your system so you can use it later
Let’s look at what we’ve done with this script:
- We included the Wildlink PHP library using the autoload feature of Composer
- We set the credentials for our client to connect to the Wildlink web service and made our connection
- We displayed our user’s Device Key, Device ID and Device Token that were automatically generated
Important Note: The Device Key and Device ID represent your user’s device and you will need to store these values in your application/database. Every new “session” you have with your user should pass the Device Key so that clicks, earnings, etc. are persisted across sessions. If you don’t pass Device Key in, you will be telling Wildlink to create a new device (which will have no earnings or other history).
You may be wondering “What’s the difference between the Device ID and Device Key?” Well, the Device ID is an integer value that Wildlink uses to reference a device in other contexts (i.e. the commissions report that describes all commissions across all devices for an application). The Device Key is instead used by the client (you) as part of the authentication, proving that you’re allowed to make requests as that device. For this reason, the Device Key should be considered sensitive data. Device ID is less sensitive since you can’t make requests using the Device ID.
So what if we want to connect to the Wildlink web service using a previously created Device Key? Here’s an example of how to pass in a pre-existing Device Key to the client creation:
$device_key = ... // get the UUID from your storage $wf_client = new WildlinkClient($app_id, $secret, $device_key);
This tells Wildlink “I want to make requests as device X” so you can check a device’s commissions, click stats, etc.
Step 3: Generating your first wild.link
Now that we have a connection to the Wildlink web service, let’s complete our example by asking Wildlink to create a wild.link Vanity URL. Add the following code to the script.
$vanity_url = $wf_client->getVanityUrl('https://www.walmart.com/ip/VIZIO-24-Class-HD-720P-LED-TV-D24hn-G9/782959488'); print_r($vanity_url->VanityURL); echo "<hr/>";
With this call we’ve asked Wildlink to take a product URL at Walmart and create a shorter Vanity URL like http://wild.link/walmart/abc123.
You’ll notice that the response includes both the VanityURL as well as the original URL so that if we make rapid asynchronous calls, we can know which request matches with which response. These Vanity URLs are now ready to embed in posts, emails or anywhere else. Any click that goes through one of these URLs that results in a purchase will earn you cash!
This completes this Getting Started guide. To explore what else you can do, try exploring the Wildlink PHP library reference.