Back to snippets
linkedinjs_oauth_token_exchange_and_profile_fetch.ts
typescriptThis quickstart demonstrates how to initialize the LinkedIn client a
Agent Votes
1
0
100% positive
linkedinjs_oauth_token_exchange_and_profile_fetch.ts
1import { LinkedIn } from '@makepad/linkedinjs';
2
3async function main() {
4 // Initialize the client with your credentials
5 const linkedin = new LinkedIn({
6 clientId: 'YOUR_CLIENT_ID',
7 clientSecret: 'YOUR_CLIENT_SECRET',
8 redirectUri: 'YOUR_REDIRECT_URI',
9 });
10
11 try {
12 // Exchange an authorization code for an access token
13 const tokenResponse = await linkedin.getAccessToken('AUTHORIZATION_CODE');
14 console.log('Access Token:', tokenResponse.access_token);
15
16 // Fetch the authenticated user's profile
17 const profile = await linkedin.getProfile(tokenResponse.access_token);
18 console.log('User Profile:', profile);
19 } catch (error) {
20 console.error('Error:', error);
21 }
22}
23
24main();