Aug 05 2019 12:19 AM
I am trying to add LinkedIn company page feed on my SharePoint Online page. But facing CORS problem. Same linkedIn share api is working fine when tested on Postman and Curl. I have also tried using with nodejs. It is showing desired result in all the cases. But when I use it in SharePoint Online, using modern script editor then it shows CORS problem.
function myFunction()
{
var accessToken='************';
var requestUri = "<LinkedIn Share API URL>";
$.ajax({
url: requestUri,
type: "GET",
async: false,
data:{count: 1},
headers: {
'Authorization': `Bearer ${accessToken}`,
'cache-control': 'no-cache',
'Access-Control-Allow-Origin':'*'
},
success: onSuccess,
error: onError
});
function onSuccess(data)
{
console.log("success: "+JSON.stringify(data));
}
function onError(error) {
console.log('LinkedIn Error: '+JSON.stringify(error));
}
}
Console Error:
Access to XMLHttpRequest at 'http://api.linkedin.com/v2/shares?q=owners&owners=urn:li:organization:********&sharesPerOwner=1&count=1&count=1' from origin 'https://spprojectstwo.sharepoint.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
Aug 05 2019 01:08 AM
@nilesh1011 Are you accessing it using spHttpClient in the page context to access the API? https://docs.microsoft.com/en-us/javascript/api/sp-http/sphttpclient?view=sp-typescript-latest
Aug 05 2019 02:52 AM
@Toby Statham I am accessing linkedIn share api through jquery Ajax method in sharePoint online modern script editor.
Aug 05 2019 03:16 AM
Not sure exactly what you're trying to do, but this doesn't look like the correct way to access the LinkedIn APIs. Where did you get this example from?
Here is the developer documentation for LinkedIn - https://docs.microsoft.com/en-us/linkedin/consumer/
Aug 05 2019 10:03 PM
We are using the webpart with No Javascript language now. When we are trying to connect the Share web api of the LinkedIn. It is giving the CORS error. I'm also attached the No Javascript typescript file for you info. API call is in the LoadData() function.
Kindly provide the help asap.
Aug 06 2019 01:19 AM
@nilesh1011 Have you added the tenant URL as an SDK in your LinkedIn application as detailed here - https://developer.linkedin.com/docs/getting-started-js-sdk
Aug 06 2019 02:24 AM
@Toby StathamWhen I click url shared by you https://developer.linkedin.com/docs/getting-started-js-sdk . It shows "The JavaScript SDK is not currently supported."
Aug 06 2019 02:42 AM
@nilesh1011 I wasn't referring to the SDK, just the section you need to add your tenant URL to.
It's slightly changed, but you need to add your tenant domain to the Widgets section in your LinkedIn app settings.
Aug 06 2019 09:19 PM
@Toby Statham Yes! I have added tenant domain to the Widgets section in my LinkedIn app settings. But still showing cors problem.
Aug 15 2022 07:15 PM