farisabun
farisabun

Reputation: 123

react-share can't share LinkedIn article

I tried to share article current URL to social media such as Facebook, Twitter & LinkedIn using react-share package. I have some issues at share the page: null (URL: https://www.linkedin.com/shareArticle/?url=https%3A%2F%2Fstaging.bidboxid.co%2Fcar-details%2Fhonda-brio-at-limited-edition&mini=true)

code:

import React from 'react';
import { LinkedinShareButton } from "react-share";
let shareUrl = window.location.href;

export default class Share extends React.Component {
   render() {
      return(
      <LinkedinShareButton url={`${shareUrl}`}>
         <div className="icon-socmed-white linkedin">
            <FaLinkedinIn/>
         </div>
      </LinkedinShareButton>)
   }
}

What weird of this case, if I tried to share the homepage page as share article it'll works just fine.

Upvotes: 3

Views: 7581

Answers (4)

user17086309
user17086309

Reputation: 11

I ran into the same problem. The old shareArticle/ url is still supported by LinkedIn by being redirected to the new sharing/share-offsite/ url -- only the optional arguments like title are ignored and crawled/grabbed automatically by LinkedIn.

So the react-share button still works.

The problem is you're feeding it a staging url -- staging.boxbid.co -- and your staging site is most likely behind a proxy and thus is not available to the LinkedIn crawler which is why it errors out.

Upvotes: 1

samuelsaumanchan
samuelsaumanchan

Reputation: 617

Posting here as I ran into the same error but managed to resolve it myself; for me the issue was that if your URL isn't resolvable by DNS the Microsoft LinkedIn API will just return "Something went wrong. Refresh the page".

I think it's implemented on the MSFT side to ensure quality of links share; so you don't just have a bunch of broken links being shared.

As long as the DNS is resolvable the REST call to the LinkedIn API to Share will work.

Hope it helps some other people out!

Upvotes: 0

HoldOffHunger
HoldOffHunger

Reputation: 20931

Maybe you should look into getting a better sharing package?

LinkedIn now only supports the url param in their social share API. They supported other params in the past, but they have always supported url-param sharing.

https://www.linkedin.com/sharing/share-offsite/?url={url}

Source: Official Microsoft LinkedIn Share API Documentation.

I mean, just try testing it out yourself:

https://www.linkedin.com/sharing/share-offsite/?url=http://www.wikipedia.org/

Works fine:

If you are interested in a regularly maintained github project that keeps track of this so you don't have to, check it out! Social Share URLs

Social Share URLs Image

Upvotes: 1

hiddenuser.2524
hiddenuser.2524

Reputation: 4988

Seems like linkedin has removed their support for sharing URLs. If you check the documentation (https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/share-on-linkedin?context=linkedin/consumer/context) it never mentions sharing using a URL.

Sharing the homepage probably still works because they missed removing support for that type of URL yet.

Most likely react-share has to be updated/will no longer support LinkedIn. You can follow the documentation above to know how to implement the sharing yourself.

LE: here is another stackoverflow answer saying the same thing: How to make a custom LinkedIn share button

Upvotes: 5

Related Questions