我使用 PHP 和 MySQL 创建了一个工作门户。现在我想创建一个 cron 作业,将作业从我的门户发布到 Indeed,并且我想将作业从 Indeed 发布到我的门户。
我在 Indeed 开发者平台上创建了 Indeed 应用程序。我在我的核心 PHP 演示中完成了以下代码。代码如下。
以下代码用于获取访问令牌:
<?php
// For getting the access token
$url = 'https://apis.indeed.com/oauth/v2/tokens';
$data = [
'grant_type' => 'client_credentials',
'client_id' => '99f0224***',
'scope' => 'employer_access',
'client_secret' => '4oJlfJXqH***'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$response = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_status == 200) {
$result = json_decode($response, true);
$access_token = $result['access_token'];
echo 'Access Token: ' . $access_token."<br><br><br>";
// For posting a job in Indeed
$job_data = [
'grant_type' => 'client_credentials',
'client_id' => '99f022474***',
'scope' => 'employer_access',
'client_secret' => '4oJlfJXqHlr9*****'
];
$job_data1 = [
"mutation" => [
"jobsIngest" => [
"createSourcedJobPostings" => [
"jobPostings" => [
[
"body" => [
"title" => "Test Job From local",
"description" => "Lorem Ipsum dolor sit amet",
"location" => [
"country" => "US",
"cityRegionPostal" => "US, NY 12345",
],
"benefits" => [],
],
"metadata" => [
"jobSource" => [
"companyName" => "Test Company",
"sourceName" => "TestCompany",
"sourceType" => "Employer",
],
"jobPostingId" => "JobId1",
"datePublished" => "2024-03-18T12:00Z",
"url" => "http://example.com/careers/job1.html",
"contacts" => [
[
"contactType" => ["contact", "recruiter"],
"contactInfo" => [
"contactEmail" => "[email protected]",
"contactPhone" => "+91324354",
"contactName" => "SL1",
],
],
],
],
],
],
],
],
],
];
$job_data = array_merge($job_data, $job_data1);
$ch1 = curl_init('https://apis.indeed.com/graphql');
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_POST, true);
curl_setopt($ch1, CURLOPT_POSTFIELDS, http_build_query($job_data));
curl_setopt($ch1, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $access_token,
'Content-Type: application/x-www-form-urlencoded',
'key:99f022474d7****'
]);
$response1 = curl_exec($ch1);
$http_status1 = curl_getinfo($ch1, CURLINFO_HTTP_CODE);
if ($http_status1 == 200) {
echo 'Job posted successfully.';
} else {
echo 'Error posting job: ' . $response1;
}
curl_close($ch1);
} else {
echo 'Error: ' . $response;
}
curl_close($ch);
我能够成功访问 access_token,但无法发布职位。我收到如下错误:
发布作业时出错:{"data":null,"errors":[{"extensions":{"code":"FORBIDDEN"},"message":"客户端未获得授权。"}]}
我也有同样的问题。我看到有一个
ATS Registration
先决条件,但我不知道 OAuth 通过后如何注册它