<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
darrynten / watson-personality-insights-php example snippets
// Required config
$config = [
'username' => $username,
'password' => $password
];
// Get an instance
$instance = new PersonalityInsights($config);
// Add some text
$text = file_get_contents('sample.txt');
$instance->addText($text);
// Get the insights
$insights = $instance->getInsights();
// Set standard options
$instance->config->setConsumptionPreferences(true);
$instance->config->setRawScores(true);
$instance->config->setVersion('2017-01-01');
$instance->config->setContentTypeHeader('application/json');
$instance->config->setContentLanguageHeader('en');
$instance->config->setAcceptHeader('application/json');
$instance->config->setAcceptLanguageHeader('en');
$instance->config->setCsvHeaders(false);
// https://watson-api-explorer.mybluemix.net/apis/personality-insights-v3#!/personality45insights/profile
// Set caching of requests
$instance->config->setCaching(false);
// Opt in to Watson tracking (off by default)
$instance->config->setOptOut(false);
// All config options
$config = [
'username' => $username,
'password' => $password,
'version' => $version,
'raw_scores' => $boolean,
'consumption_preferences' => $boolean,
'cache' => $boolean,
];
/**
* All possible content item config options. Only the `text` one is
* v3#!/personality45insights/profile
*
* Defaults
*
* id - An md5 of the text
* created - 0
* updated - 0
* contenttype - 'text/plain'
* language - en
* parentid - null
* reply - false
* forward - false
*/
$contentConfig = [
'text' => $text, // The only 'reply' => $boolean, // Indicates if it is a reply to another
'forward' => $boolean, // Indicates if it is a forwarded text
];
$contentItem = new ContentItem($contentConfig);
$contentItem->getContentItemJson();
$instance->addNewContentItem($contentItem);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.