src/Service/CallApiService.php line 69
<?phpnamespace App\Service;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Contracts\HttpClient\HttpClientInterface;class CallApiService{private $client;public function __construct(HttpClientInterface $client){$this->client = $client;}public function callApi($page): ?array{$range = "0-9";if ($page != null) {$max = 9 * $page;$min = $max - 9;$range = $min . '-' . $max;}$token = $this->client->request('POST','https://entreprise.pole-emploi.fr/connexion/oauth2/access_token?realm=%2Fpartenaire',['headers' =>['Content-Type' => 'application/x-www-form-urlencoded'],'body' =>['client_id' => 'PAR_forumindustriebourges_9ee63d8fe636d39dcccd61e7a0bdd1ba8533c68d53fc0ec77b89035bd135569e','client_secret' => '9bdd37f789dd7ddd36cfc2c5b9f58131beb9241dfc6cc49ac61d38b774626815','grant_type' => 'client_credentials','scope' => 'api_offresdemploiv2 o2dsoffre']]);$content= json_decode($token->getContent(), true);$access_token = $content['access_token'];$response = $this->client->request('GET','https://api.pole-emploi.io/partenaire/offresdemploi/v2/offres/search',['headers' =>['Authorization' => 'Bearer ' . $access_token,],'query' => ['range' => $range,'grandDomaine' => 'H,I,N','departement' => '18','sort' => '1',]]);$data = json_decode($response->getContent(), true);return $data;}public function searchKeyword($motcle,$page){$range = "0-9";if ($page != null) {$max = 9 * $page;$min = $max - 9;$range = $min . '-' . $max;}$motcle = str_replace('+', ',', $motcle);// Effectuer la requête à l'API de Pôle emploi$token = $this->client->request('POST','https://entreprise.pole-emploi.fr/connexion/oauth2/access_token?realm=%2Fpartenaire',['headers' =>['Content-Type' => 'application/x-www-form-urlencoded'],'body' =>['client_id' => 'PAR_forumindustriebourges_9ee63d8fe636d39dcccd61e7a0bdd1ba8533c68d53fc0ec77b89035bd135569e','client_secret' => '9bdd37f789dd7ddd36cfc2c5b9f58131beb9241dfc6cc49ac61d38b774626815','grant_type' => 'client_credentials','scope' => 'api_offresdemploiv2 o2dsoffre']]);$content= json_decode($token->getContent(), true);$access_token = $content['access_token'];$response = $this->client->request('GET','https://api.pole-emploi.io/partenaire/offresdemploi/v2/offres/search',['headers' =>['Authorization' => 'Bearer ' . $access_token,],'query' => ['range' => $range,'grandDomaine' => 'H,I,N','departement' => '18','motsCles' => $motcle]]);$data = json_decode($response->getContent(), true);return $data;}}