PHP code example of sentimo / php-client

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

    

sentimo / php-client example snippets


use Sentimo\Client\HttpClient\ClientFactory;

$apiKey = 'your-api-key-here';
$clientFactory = new ClientFactory();
$client = $clientFactory->createClient($apiKey);

use Sentimo\Client\Api\Data\ReviewInterface;
use Sentimo\Client\Api\Data\AuthorInterface;
use Sentimo\Client\Api\Data\ProductInterface;

// Example Review, Author, and Product objects (these would be created according to your implementation)
$review = new class implements ReviewInterface {
// Implement the methods of ReviewInterface
};

$reviews = [$review];
$channel = 'your-channel'; // Optional

try {
    $postedReviewIds = $client->postReviews($reviews, $channel);
    echo 'Posted Reviews: ' . implode(', ', $postedReviewIds);
} catch (LocalizedException $e) {
    echo 'Error posting reviews: ' . $e->getMessage();
    
}

use Sentimo\Client\RequestParam\ReviewGetRequestParamBuilder;

$paramBuilder = new ReviewGetRequestParamBuilder();
$paramBuilder->setExternalIds(['external-id-1', 'external-id-2'])
             ->setModerationStatus('approved');

try {
    $reviews = $client->getReviews($paramBuilder, true); // true to fetch all pages
    foreach ($reviews as $review) {
        // Process each review
    }
} catch (LocalizedException $e) {
    echo 'Error fetching reviews: ' . $e->getMessage();
}


try {
    $postedReviewIds = $client->postReviews($reviews, $channel);
} catch (LocalizedException $e) {
    // Handle the error
}

$errors = $client->getErrors();
if (!empty($errors)) {
    foreach ($errors as $error) {
        echo $error . PHP_EOL;
    }
}
bash
composer