1. Go to this page and download the library: Download stajor/perspectiveapi 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/ */
stajor / perspectiveapi example snippets
$commentsClient = new PerspectiveApi\CommentsClient('PERSPECTIVE-API-TOKEN');
$commentsClient->comment(['text' => 'What kind of idiot name is foo? Sorry, I like your name.']);
$commentsClient->languages(['en']);
$commentsClient->context(['entries' => ['text' => 'off-topic', 'type' => 'PLAIN_TEXT']]);
$commentsClient->requestedAttributes(['TOXICITY' => ['scoreType' => 'PROBABILITY', 'scoreThreshold' => 0]]);
// Analyze and get response
$response = $commentsClient->analyze();
// Print scores
print_r($response->attributeScores());
$commentsClient = new PerspectiveApi\CommentsClient('PERSPECTIVE-API-TOKEN');
$commentsClient->comment(['text' => 'What kind of idiot name is foo? Sorry, I like your name.']);
$commentsClient->languages(['en']);
$commentsClient->context(['entries' => ['text' => 'off-topic', 'type' => 'PLAIN_TEXT']]);
$commentsClient->clientToken('some-token');
$commentsClient->communityId('unit-test');
$commentsClient->attributeScores(['TOXICITY' => [
'summaryScore' => ['value' => 0.83785176, 'type' => 'PROBABILITY'],
'spanScores' => [['begin' => 0, 'end' => 32, 'score' => ['value' => 0.9208521, 'type' => 'PROBABILITY']]]]
]);
// Suggest Score and get response
$response = $commentsClient->suggestScore();
// Print scores
print_r($response->attributeScores());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.