type Linkedin = {
token: string
apiVersion: string
}
export async function main(resource: Linkedin, entityUrn: string, maxResults: number = 100) {
const count = 50 // Number of results per request
const results: any[] = []
const encodedEntityUrn = encodeURIComponent(entityUrn)
let params = new URLSearchParams({
count: count.toString(),
start: '0'
})
let done = false
do {
const endpoint = `https://api.linkedin.com/rest/socialActions/${encodedEntityUrn}/comments?${params.toString()}`
const response = await fetch(endpoint, {
method: 'GET',
headers: {
Authorization: `Bearer ${resource.token}`,
'X-Restli-Protocol-Version': '2.0.0',
'LinkedIn-Version': `${resource.apiVersion}`
}
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
results.push(...data.elements)
params.set('start', (parseInt(params.get('start')!) + count).toString())
if (data.elements.length < count || results.length >= maxResults) {
done = true
}
} while (!done)
return results.slice(0, maxResults)
}
Submitted by hugo697 158 days ago
type Linkedin = {
token: string
apiVersion: string
}
export async function main(resource: Linkedin, entityUrn: string, maxResults: number = 100) {
const count = 50 // Number of results per request
const results: any[] = []
const encodedEntityUrn = encodeURIComponent(entityUrn)
let params = new URLSearchParams({
count: count.toString(),
start: '0'
})
let done = false
do {
const endpoint = `https://api.linkedin.com/rest/socialActions/${encodedEntityUrn}/comments?${params.toString()}`
const response = await fetch(endpoint, {
method: 'GET',
headers: {
Authorization: `Bearer ${resource.token}`,
'X-Restli-Protocol-Version': '2.0.0',
'LinkedIn-Version': `${resource.apiVersion}`
}
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
results.push(...data.elements)
params.set('start', (parseInt(params.get('start')!) + count).toString())
if (data.elements.length < count || results.length >= maxResults) {
done = true
}
} while (!done)
return results.slice(0, maxResults)
}
Submitted by hugo697 158 days ago