PHP code example of andy87 / php-client-hh
1. Go to this page and download the library: Download andy87/php-client-hh 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/ */
andy87 / php-client-hh example snippets
declare(strict_types=1);
Hh;
use and_y87\ClientsHh\Generated\Prompt\GetVacanciesPrompt;
$client = new ApiClientHh([
'headers' => [
'HH-User-Agent' => 'my-app/1.0 ([email protected] )',
],
]);
$prompt = new GetVacanciesPrompt();
$prompt->text = 'php developer';
$prompt->per_page = 10;
$response = $client->vacancySearch->getVacancies($prompt);
foreach ($response->items ?? [] as $vacancy) {
echo $vacancy->name . PHP_EOL;
}
use and_y87\ClientsHh\ApiClientHh;
use and_y87\ClientsHh\Generated\Prompt\GetCurrentUserInfoPrompt;
use and_y87\ClientsHh\Generated\ProviderKey;
$client = new ApiClientHh([
'accessToken' => 'your-oauth-access-token',
'headers' => [
'HH-User-Agent' => 'my-app/1.0 ([email protected] )',
],
]);
$response = $client->provider(ProviderKey::CurrentUser)->getCurrentUserInfo(new GetCurrentUserInfoPrompt());
echo $response->id . PHP_EOL;
use and_y87\ClientsHh\ApiClientHh;
$client = new ApiClientHh([
'access_token' => 'your-oauth-access-token',
'base_url' => 'https://api.hh.ru',
'token_url' => 'https://hh.ru/oauth/token',
'timeout' => 30,
'headers' => [
'HH-User-Agent' => 'my-app/1.0 ([email protected] )',
],
]);
use and_y87\ClientsHh\ApiClientHh;
use and_y87\ClientsHh\HhConfig;
$client = new ApiClientHh(HhConfig::fromEnv());
use and_y87\ClientsHh\ApiClientHh;
use and_y87\PhpClientSdk\Client\Event\BeforeRequestEvent;
$client = new ApiClientHh([
'accessToken' => 'your-oauth-access-token',
], [
ApiClientHh::HEADERS => [
'HH-User-Agent' => 'my-app/1.0 ([email protected] )',
],
ApiClientHh::EVENTS => [
ApiClientHh::EVENT_BEFORE_REQUEST => static function (BeforeRequestEvent $event): void {
$event->request->headers['X-Trace-Id'] = bin2hex(random_bytes(8));
},
],
]);
bash
composer