CORS阻止LinkedIn分享API [英] CORS blocks LinkedIn share api

查看:184
本文介绍了CORS阻止LinkedIn分享API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过LinkedIn的AngularJS应用程序中的JavaScript通过LinkedIn共享API发布新内容.

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');
});

我可以成功发布该数据.但是,浏览器阻止读取响应,因为该响应没有"Access-Control-Allow-Origin"标头.

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.

但是,我在LinkedIn应用程序中提供了http://localhost:3000和' https://localhost:3000 '域设置.

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

Chrome中的请求/响应如下所示.

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 ?

我认为问题是LinkedIn API响应中缺少Access-Control-Allow-Origin标头?

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

推荐答案

好像LinkedIn的REST API不支持CORS.他们建议从后端而不是从浏览器使用REST API.必须在浏览器中使用JS-SDK.

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

这篇关于CORS阻止LinkedIn分享API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆