CORS blocks LinkedIn share api

大城市里の小女人 提交于 2019-11-28 07:48:40

问题


I try to post new content using LinkedIn share API through JavaScript from AngularJS application as given below.

var xml = "<share><comment>" + content + "</comment><visibility><code>anyone</code></visibility></share>";

var req = {
   method: 'POST',
   url: 'https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=' + account.token,
   headers: {
       'Content-Type': 'text/plain'
   },
   data: xml
};

$http(req).success(function(data) {
   console.log(data);
   console.log('published to linkedin');
}).error(function() {
   console.log(arguments);
   console.log('failed to publish to linkedin');
});

I can successfully POST this data. However the browser blocks the response from being read because the response doesn't have an 'Access-Control-Allow-Origin' header.

But, I have given the http://localhost:3000 and 'https://localhost:3000' domains in LinkedIn application settings.

And the request/response in Chrome looks like this.

Any thoughts on how to be able to read the response and not let the browser block it ?

I think the problem is the missing Access-Control-Allow-Origin header in the LinkedIn API response ?


回答1:


Looks like LinkedIn's REST API doesn't support CORS. They suggest to use REST API from the backend and not from browser. JS-SDK must be used from the browser.

https://developer-programs.linkedin.com/forum/cors



来源:https://stackoverflow.com/questions/29512646/cors-blocks-linkedin-share-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!