src/Service/CallApiService.php line 18
<?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_salondelindustrie41_fe3f55099e765f46c092b25f44880cdf0c3ac624de2bf615b4dfd3e4d1e38a3d','client_secret' => 'b62c2085f7dde17e8d10eda93729c870f66ec7d39a2ecd139a02917191d1390b','grant_type' => 'client_credentials','scope' => 'api_offresdemploiv2 o2dsoffre']])// ->getContent();// $httpLogs = $token->getInfo('debug');// dump(json_decode($token->getContent('access_token')));// dump($httpLogs);$content= json_decode($token->getContent(), true);$access_token = $content['access_token'];//dump($access_token);$response = $this->client->request('GET','https://api.pole-emploi.io/partenaire/offresdemploi/v2/offres/search',['headers' =>['Authorization' => 'Bearer ' . $access_token,],'query' => [// Nb d'annonces'range' => $range,// Tri par mot-clé// 'motsCles' => '',// H -> Industrie// I -> Installation / Maintenance// N -> Transport / Logistique'grandDomaine' => 'H,I,N','departement' => '41',// 0 -> Tri par pertinence décroissante, distance croissante, date de création décroissante// 1 -> Tri par date de création décroissant, pertinence décroissante, distance croissante// 2 -> Tri par distance croissante, pertinence décroissante, date de création décroissante'sort' => '1',// Tri par domaine// 'grandDomaine' => 'Commerce / Vente',// Tri par commune// 'commune' => '44109', // code INSEE de la commune//'commune' => '41018,41194,41269,41295,41136,41232,41242,41106,41047,41149,41059,41212,41151,41167,41226,41150,41198',// 'distance' => '0',]]);$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;}// dump($motcle);$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_salondelindustrie41_fe3f55099e765f46c092b25f44880cdf0c3ac624de2bf615b4dfd3e4d1e38a3d','client_secret' => 'b62c2085f7dde17e8d10eda93729c870f66ec7d39a2ecd139a02917191d1390b','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' => [// Nb d'annonces sur la page'range' => $range,// H -> Industrie// I -> Installation / Maintenance// N -> Transport / Logistique'grandDomaine' => 'H,I,N','departement' => '41','motsCles' => $motcle]]);// dump($response->getStatusCode());$data = json_decode($response->getContent(), true);return $data;}}