PHP code example of smartlyq / sdk

1. Go to this page and download the library: Download smartlyq/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/ */

    

smartlyq / sdk example snippets


use Smartlyq\SmartlyQ;

$sq = new SmartlyQ(getenv('SMARTLYQ_API_KEY'));

// Who am I?
$me = $sq->account->getMe();

// Generate an image with AI
$image = $sq->images->generate(['prompt' => 'A minimalist product shot of a smart speaker']);

// Publish a social post
$post = $sq->social->createPost([
    'text' => 'Hello from the SmartlyQ SDK!',
    'account_ids' => ['acc_123'],
]);

$sq = new SmartlyQ('sqk_live_xxxxxxxxxxxx', [ // or omit the key and set SMARTLYQ_API_KEY
    'timeout' => 60,        // per-request timeout in seconds
    'max_retries' => 2,     // automatic retries on 429/5xx
]);

$sq->social->createPost($body, [
    'idempotency_key' => 'my-unique-key',  // safe retries for writes
    'profile_id' => 'prof_123',            // act on behalf of a managed Profile
    'timeout' => 10,
]);

$video = $sq->videos->generate(['prompt' => 'A 5s product teaser', 'model' => 'standard']);

$job = $sq->jobs->get($video['data']['job_id']);
while (in_array($job['data']['status'], ['processing', 'queued'], true)) {
    sleep(3);
    $job = $sq->jobs->get($video['data']['job_id']);
}
print_r($job['data']['result']);

use Smartlyq\SmartlyQError;

try {
    $sq->articles->generate(['topic' => 'AI trends']);
} catch (SmartlyQError $e) {
    echo $e->getStatusCode();   // e.g. 422
    echo $e->getErrorCode();    // e.g. "validation_error"
    echo $e->getMessage();      // human-readable message
    echo $e->getRequestId();    //