CORS 阻止 LinkedIn 共享 API [英] CORS blocks LinkedIn share API
问题描述
我尝试使用 LinkedIn share API 通过 JavaScript 从 AngularJS 应用程序发布新内容,如下所示.
var xml = ""+ 内容 + "</comment><visibility><code>anyone</code></visibility></share>";变量请求 = {方法:'POST',url: 'https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=' + account.token,标题:{'内容类型':'文本/纯文本'},数据:xml};$http(req).success(function(data) {控制台日志(数据);console.log('发布到linkedin');}).错误(函数(){控制台日志(参数);console.log('无法发布到linkedin');});
我可以成功发布这些数据.但是浏览器会阻止读取响应,因为响应没有Access-Control-Allow-Origin"标头.
但是,我已经给出了 http://localhost:3000
和 '
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?
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屋!