admin管理员组文章数量:1279124
I try to post new content using LinkedIn share API through JavaScript from AngularJS application as given below.
var xml = "<share><ment>" + content + "</ment><visibility><code>anyone</code></visibility></share>";
var req = {
method: 'POST',
url: '=' + 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?
I try to post new content using LinkedIn share API through JavaScript from AngularJS application as given below.
var xml = "<share><ment>" + content + "</ment><visibility><code>anyone</code></visibility></share>";
var req = {
method: 'POST',
url: 'https://api.linkedin./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?
- You should look into the JS SDK, developer.linkedin./docs/js-sdk – C3roe Commented Apr 8, 2015 at 11:19
- @ritesh: “yes,you have to set the header” – he can not set that header for a service that he doesn’t have control over. – C3roe Commented Apr 8, 2015 at 11:20
- @CBroe I am using the rest api documented at developer.linkedin./docs/rest-api. Not the JS SDK. – Raju Mandapati Commented Apr 8, 2015 at 11:27
- Yeah, I got that. However, the JS SDK is provided specifically to make using their API from JavaScript easier … – C3roe Commented Apr 8, 2015 at 11:45
-
@CBroe I tried using the JS SDK. But I get a
400 Bad Request
. Coming back to REST API, why doesn't LinkedIn send anAccess-Control-Allow-Origin
header ? Am I missing something ? – Raju Mandapati Commented Apr 8, 2015 at 12:27
1 Answer
Reset to default 11Looks 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./forum/cors
本文标签: javascriptCORS blocks LinkedIn share APIStack Overflow
版权声明:本文标题:javascript - CORS blocks LinkedIn share API - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741260610a2367548.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论