Created
May 25, 2023 12:10
-
-
Save felladrin/c4cf2eb7afbfb4988d3fb5a973a8e32b to your computer and use it in GitHub Desktop.
JavaScript to list the articles you published on LinkedIn. Read more at https://learn.microsoft.com/en-us/linkedin/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const accessToken = 'YOUR_LINKEDIN_ACCESS_TOKEN'; | |
async function getLinkedinArticles() { | |
const response = await fetch( | |
`https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,articles)`, | |
{ | |
headers: { | |
'Authorization': `Bearer ${accessToken}`, | |
'cache-control': 'no-cache', | |
}, | |
} | |
); | |
if (response.ok) { | |
const data = await response.json(); | |
const articles = data.articles.elements; | |
articles.forEach((article) => { | |
const { title, date, url } = article; | |
console.log(`Date: ${date}`); | |
console.log(`Title: ${title}`); | |
console.log(`Link: ${url}`); | |
}); | |
} else { | |
console.error('Error retrieving published articles:', response.status); | |
} | |
} | |
getLinkedinArticles(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment