我正在努力将 LinkedIn 的 API 集成到我的 React 应用程序中,以代表我们的组织发布职位。我已获得具有以下权限的访问令牌:
w_organization_social
w_member_social
r_organization_social
r_member_social
const config = { headers: { Authorization: `Bearer ${ACCESS_TOKEN}`, "Content-Type": "application/json", "LinkedIn-Version": "202401", "x-restli-protocol-version": "2.0.0", }, };
const requestBody = { author: `urn:li:person:${PERSON_ID}`, commentary: "Your job posting description here", visibility: "PUBLIC", distribution: { feedDistribution: "MAIN_FEED", targetEntities: [], thirdPartyDistributionChannels: [], }, lifecycleState: "PUBLISHED", elements: [ { integrationContext: `urn:li:organization:${ORG_ID}`, companyApplyUrl: "https://cubiclogics.com", externalJobPostingId: "12345", jobPostingOperationType: "CREATE", title: "Software Developer in Test", description: "Your detailed job description here", listedAt: Date.now(), location: "Sunnyvale, California", categories: ["rsch"], industries: ["urn:li:industry:55"], skillsDescription: "Required skills: JavaScript, Python, HTML/CSS", companyJobCode: "company_12345", employmentStatus: "FULL_TIME", experienceLevel: "EXECUTIVE", trackingPixelUrl: "http://www.trackingpixellocation.com/pixel.gif", listingType: "BASIC", }, ], };
//This is my code
async function postJobToLinkedIn() {
try {
let res = await axios.post(
"https://api.linkedin.com/rest/posts",
requestBody,
config
);
console.log(res, "res from api");
} catch (error) {
console.error(
"Error posting job:",
error.response ? error.response.data : error.message
);
}
}
//Response
{
"message": "ERROR :: /elements :: unrecognized field found but not allowed",
"status": 422
}
我收到 422 状态错误,消息表明 /elements 字段无法识别。
我尝试过的:
事实上,用于发布职位的 LinkedIn API 不支持
elements
字段。/simpleJobPostings
端点发布,而不是 /posts
。