LinkedIn: look up company Page names in one batch call

Single-Page lookups hit LinkedIn's daily per-member limit for admins of many Pages,
so the Page list fell back to ids.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
metatroncubeswdev 2026-10-28 22:15:00 -04:00
parent 1307146921
commit 41da5b3968
2 changed files with 10 additions and 6 deletions

View File

@ -83,12 +83,16 @@ export default {
const out = [{ id: `urn:li:person:${account.id}`, name: `${account.name} (personal profile)` }];
try {
const { data } = await request("LinkedIn", `${API}/rest/organizationAcls`, { ...rest(tokens.accessToken), query: { q: "roleAssignee", role: "ADMINISTRATOR", state: "APPROVED" } });
for (const e of data.elements || []) {
const orgId = String(e.organization).split(":").pop();
let name = `Company ${orgId}`;
try { name = (await request("LinkedIn", `${API}/rest/organizations/${orgId}`, rest(tokens.accessToken))).data.localizedName || name; } catch { /* keep id */ }
out.push({ id: e.organization, name: `${name} (company Page)` });
const ids = (data.elements || []).map((e) => String(e.organization).split(":").pop());
// One batch call per 50 Pages: single-Page lookups have a small daily limit per member.
const names = {};
for (let i = 0; i < ids.length; i += 50) {
try {
const r = await request("LinkedIn", `${API}/rest/organizations?ids=List(${ids.slice(i, i + 50).join(",")})`, rest(tokens.accessToken));
for (const [id, o] of Object.entries(r.data.results || {})) names[id] = o.localizedName;
} catch { /* keep ids */ }
}
for (const id of ids) out.push({ id: `urn:li:organization:${id}`, name: `${names[id] || `Company ${id}`} (company Page)` });
} catch { /* no organization scopes: personal profile only */ }
return out;
},

View File

@ -141,7 +141,7 @@ test("LinkedIn: connect, list company Pages, post image to a company Page", asyn
const { conn } = await connect("linkedin", "acme", { identify: [
["GET", "https://api.linkedin.com/v2/me", json({ id: "abc", localizedFirstName: "Pat", localizedLastName: "Lee" })],
["GET", "https://api.linkedin.com/rest/organizationAcls", json({ elements: [{ organization: "urn:li:organization:42" }] })],
["GET", "https://api.linkedin.com/rest/organizations/42", json({ localizedName: "Acme Co" })],
["GET", "https://api.linkedin.com/rest/organizations?ids=List(42)", json({ results: { 42: { localizedName: "Acme Co" } } })],
] });
assert.equal(conn.account.name, "Pat Lee");
const targets = await P.targetsFor(conn.id);