Skip to content

Instantly share code, notes, and snippets.

@felladrin
Created May 25, 2023 12:10
Show Gist options
  • Save felladrin/c4cf2eb7afbfb4988d3fb5a973a8e32b to your computer and use it in GitHub Desktop.
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/
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