PHP code example of qaamgo / onlineconvert-api-sdk
1. Go to this page and download the library: Download qaamgo/onlineconvert-api-sdk 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/ */
qaamgo / onlineconvert-api-sdk example snippets
$client = new Api2Convert\Api2Convert('YOUR_API_KEY');
$client->convert('photo.png', 'jpg')->save('photo.jpg');
$config = new \OnlineConvert\Configuration();
$config->setApiKey('main', 'HERE YOUR API KEY');
$client = new \OnlineConvert\Client\OnlineConvertClient($config, 'main');
$syncApi = new \OnlineConvert\Api($client);
$asyncApi = new \OnlineConvert\Api($client, true);
$config = new \OnlineConvert\Configuration();
$config->setApiKey('main', 'PUT YOUR API KEY HERE');
// Remember to specify your own downloads folder. The SDK does not create it for you —
// downloading into a folder that does not exist fails with a Guzzle RuntimeException.
$downloadFolder = __DIR__ . '/downloads';
if (!is_dir($downloadFolder) && !mkdir($downloadFolder, 0775, true) && !is_dir($downloadFolder)) {
throw new \RuntimeException('Could not create the download folder: ' . $downloadFolder);
}
$config->downloadFolder = $downloadFolder;
$client = new \OnlineConvert\Client\OnlineConvertClient($config, 'main');
$syncApi = new \OnlineConvert\Api($client);
$outputEndpoint = $syncApi->getOutputEndpoint();
$syncJob = [
'input' => [
[
'type' => \OnlineConvert\Endpoint\InputEndpoint::INPUT_TYPE_REMOTE,
'source' => 'PUT URL HERE'
]
],
'conversion' => [
[
'target' => 'jpg'
]
]
];
$job = $syncApi->postFullJob($syncJob)->getJobCreated();
// You will find the file/s in the downloads folder
$outputEndpoint->downloadOutputs($job);
$config = new \OnlineConvert\Configuration();
$client = new \OnlineConvert\Client\OnlineConvertClient($config);
$syncApi = new \OnlineConvert\Api($client);
$ep = $syncApi->getJobsEndpoint();
//Option 1
$ep->getClient()->setHeader(\OnlineConvert\Client\Interfaced::HEADER_OC_API_KEY, 'YOUR API KEY');
//Option 2 (every endpoint shares the same client instance, so this affects $ep too)
//$client->setHeader(\OnlineConvert\Client\Interfaced::HEADER_OC_API_KEY, 'YOUR API KEY');
$job = $ep->postJob([]);
$ip = $syncApi->getInputEndpoint();
//WORK WITH TOKENS
//OPTION 1
$input = $ip->setUserToken($job['token'])->postJobInputRemote('https://www.online-convert.com/', $job['id']);
//Option 2 (Apply also the previous options to set a header)
//$ip->getClient()->setHeader(\OnlineConvert\Client\Interfaced::HEADER_OC_JOB_TOKEN, $job['token']);
//$input = $ip->postJobInputRemote('https://www.online-convert.com/', $job['id']);
var_dump($job, $input);