PHP code example of alldebrid / alldebrid-php

1. Go to this page and download the library: Download alldebrid/alldebrid-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alldebrid / alldebrid-php example snippets




$agent = 'myAppName'; // Your project name
$apikey = 'YYYYYY'; // Apikey

$alldebrid = new \Alldebrid\Alldebrid($agent, $apikey);

$agent = 'myAppName'; // Your project name
$apikey = 'YYYYYY'; // Apikey

$alldebrid = new \Alldebrid\Alldebrid($agent, $apikey);

// Go-style, always return an array [ $response, $error ]
[ $user, $error ] = $alldebrid->user();

if($error) {
    // Api call failed or returned an error
    $errorMessage = $user;
    die("Could not get user informations, error " . $error . " : " . $errorMessage . "\n");
}

// No error, you can consume the response 
echo "Hello, " . $user['username'] . "\n";

$agent = 'myAppName'; // Your project name
$apikey = 'YYYYYY'; // Apikey

$alldebrid = new \Alldebrid\Alldebrid($agent, $apikey);
$alldebrid->setErrorMode('exception');

try {
    $user = $alldebrid->user();
} catch(Exception $e) {
    die("Exception " . $e->getMessage() . "\n");
}

// No error, you can consume the response 
echo "Hello, " . $user['username'] . "\n";

$alldebrid = new \Alldebrid\Alldebrid($agent, $apikey);
$myLink = 'https://example.com/example';
[ $response, $error ] = $alldebrid->api('link/infos', ['link' => [ $myLink ] ]);

$alldebrid = new \Alldebrid\Alldebrid($agent, $apikey);
$myLink = 'https://example.com/example';
[ $response, $error ] = $alldebrid->linkInfos($myLink);

$alldebrid = new \Alldebrid\Alldebrid($agent, $apikey);
$myLink = 'https://example.com/example';

$link = $alldebrid->link($myLink);
[ $response, $error ] = $link->infos();
//  you can then call $link->unlock() if there is no error 

$alldebrid = new \Alldebrid\Alldebrid($agent, $apikey);

// By default retry=true and maxRetries=2, the library will retry failed request 2 times
$alldebrid->options['retry'] = false; // Disable retry
$alldebrid->options['maxRetries'] = 5; // Raise max retries 

// By default autoInit=false, the library wont make any api call you didn't request explicitly
$alldebrid->options['autoInit'] = true; // Get user and hosts informations on wrapper creation

// By default autoUnlockBestStreamQuality=false
$alldebrid->options['autoUnlockBestStreamQuality'] = true; // On link with multiple stream options, the library will automatically unlock the highest quality source

// By default ignoreRedirector=true
$alldebrid->options['ignoreRedirector'] = true; // Flag to make the library handle redirectors

// By default exceptions=false
$alldebrid->options['exceptions'] = true; // Use Exception for error handling. Can also use $alldebrid->setErrorMode('exception');