1

Why does the below not return a 401 status, but instead fails miserably?

$.ajax({
     url: "https://api.linkedin.com/v1/people/~",
     //jsonpCallback: "callback",
     //dataType: "jsonp",
     success: function(data, textStatus, xhr) {
         console.log(data)
     },
     error: function(xhr, textStatus, error) {
         console.log(xhr)
     }
 });
Sibeesh Venu
  • 12,177
  • 5
  • 67
  • 98
chrism
  • 38
  • 3

1 Answers1

0

Your request is not authenticated therefore it isn't allowed access.
Follow the steps here to perform an authenticated request: https://developer.linkedin.com/docs/oauth2#

Andrew A.
  • 770
  • 2
  • 10
  • 21
  • I don't think so. I also called with a valid token in oauth_access_token query string and still failed instead of returning a 401. – chrism Jan 30 '18 at 15:46
  • looking at the console, there is a message: `Failed to load https://api.linkedin.com/v1/people/~: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://fiddle.jshell.net' is therefore not allowed access. The response had HTTP status code 401.` Regular web pages can use the XMLHttpRequest object to send and receive data from remote servers, but they're limited by the same origin policy. You're using jQuery though, so not sure if that needs to first request cross-origin permissions. – Andrew A. Jan 30 '18 at 15:51
  • Yup, you are correct in Chrome. FF was not showing the CORS violation (even with a valid oauth_access_token). Soooo, is there anyway around this besides using LI JS SDK? – chrism Jan 30 '18 at 16:02
  • Apart from using the LI SDK, you can actually disable CORS (though this isn't recommended) in chrome and other browsers. Chrome has some plugins or you can do it yourself manually. This answer has some steps on how to do it: https://stackoverflow.com/a/3177718/3968358. – Andrew A. Jan 30 '18 at 16:09
  • Thank you. That gets me one step further. – chrism Jan 30 '18 at 16:21