0

I am trying to post a Share to LinkedIn using OAuth v2 - I have got authorisation correctly and have the appropriate access keys. This code is supposed to share a link on LinkedIn, but for some reason it's not working - I'm not sure why. Can anyone help? this is my request body:

{
  "distribution": {
      "linkedInDistributionTarget": {}
  },
  "owner": "urn:li:person:XXXXXX",
  "subject": "Test Share Subject",
  "text": {
      "text": "Hello !"
  }

And this my call API shares :

  publishPostLink(body : any, token : any){
this.headers = new HttpHeaders(
  {
    'Content-Type': 'application/json',
    'Authorization':'Bearer '+token, 
    'cache-control': 'no-cache', 
    'X-Restli-Protocol-Version':'2.0.0', });    
return this.http.post("https://api.linkedin.com/v2/shares" , body, {headers: this.headers});}

I get this issue:

I've already installed the Moesif CORS and it didn't worked

I fixed the error using this post.. it should use REST API from the backend and not from frontend

  • `Access-Control-Allow-Methods`, `Access-Control-Allow-Origin`, `Access-Control-Allow-Credentials`, and `Access-Control-Allow-Methods` are HTTP *response* headers. You don't need to send those to LinkedIn, in any case. Plus, you're putting the token on the query string and in the `Authorization` header. Surely both aren't needed. Maybe clean that up a bit and, if it still doesn't work, edit your question so we can more clearly see where the problem lies. – Travis Spencer Aug 30 '20 at 08:29
  • I edited the code but it still the same problem and the same error. – Amira Messoud Aug 31 '20 at 07:30
  • I fixed the error using this post.. [it should use REST API from the backend and not from frontend](https://stackoverflow.com/questions/29512646/cors-blocks-linkedin-share-api) – Amira Messoud Sep 01 '20 at 15:18
  • So, just wrong API? Maybe add that as an answer. – Travis Spencer Sep 01 '20 at 16:01

1 Answers1

0

http://localhost is an insecure request origin so its not supportted in many cases. Try using tunneling software like Ngork https://ngrok.com/