I have a small node application that is retrieving an access token from LinkedIn after authenticating (authorizing) with Oath2.
Now that I have the token I want to make a subsequent request to get a users profile data. The problem is that when I make the request the error says the following:
{"success":false,"msg":"403 - {\"serviceErrorCode\":100,\"message\":\"Not enough permissions to access: GET /me\",\"status\":403}"}
I've checked off all the "state" options in the LinkedIn app.
According to the LinkedIn API docs the token needs to be sent in a header. Like this:
( reference: https://developer.linkedin.com/docs/oauth2#requests )
The route to get profile data is listed as: https://api.linkedin.com/v2/me
Here is the route that I want users to hit to get their profile data:
app.get("/user",async (req,res)=>{
console.log(token); /* token object is available in higher scope from previous request */
var options = {
url: "https://api.linkedin.com/v2/me",
method: 'GET',
headers: {
'Host': "api.linkedin.com",
'Connection': "Keep-Alive",
'Authorization': 'Bearer ' + token.access_token
},
json: true // Automatically stringifies the body to JSON
};
try {
var response = await makeRequest(options);
return res.json({success:true})
} catch (err) {
return res.json({ success: false, msg: err.message});; // TypeError: failed to fetch
}
});
Try adding a space after the word Bearer. Currently it sees your token and the word Bearer
as a single string and it doesn't know where to split to get the token
'Authorization': 'Bearer ' + token.access_token
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With