PHP code example of somin-team / somin-api-sdk
1. Go to this page and download the library: Download somin-team/somin-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/ */
somin-team / somin-api-sdk example snippets
$requester = new SimpleHttpRequester();
$authorizer = new CredentialsAuthorizer($requester);
$tokenRequest = (new UserCredential())
->setUsername(USERNAME)
->setPassword(PASSWORD);
// Call authorization method
$tokenResponse = $authorizer->auth($tokenRequest);
// Set bearer token to current HttpRequester
$requester->setBearer($tokenResponse->getToken());
$request = (new UserProfileData())
->setTexts([
"Hello friend!",
"The weather is good :)"
])
->setImageURLs([
"https://pbs.twimg.com/media/C6ij4CLUwAAxu9r.jpg",
"https://pbs.twimg.com/media/C6jO3UiVoAQYc_8.jpg"
])
->setLang('en')
->withAgeGroup()
->withEducationLevel()
->withGender()
->withIncome()
->withOccupation()
->withRelationship();
$userProfiler = new IndividualUserProfiler($requester);
// Call individual user profile method and get request id
$requestResponse = $userProfiler->predictIndividualUserProfile($request);
$request = (new ResponseRequest())
->setRequestID($requestResponse->getRequestId())
->setResponseClass(IndividualUserProfile::class);
// Call method for check current request status
$commonProcessor = new CommonProcessor($this->requester);
$numAttempts = 10;
$response = null; /** @var $response IndividualUserProfile */
while($numAttempts-- > 0 && ($response == null || $response->getHttpCode() !== 200)) {
sleep(self::RESPONSE_WAIT_TIME_SECONDS);
$response = $commonProcessor->response($request);
}
var_dump($response);