react-share icon indicating copy to clipboard operation
react-share copied to clipboard

sharing via facebook messenger doesn't work on mobile devices

Open achraf-boussaada opened this issue 5 years ago • 8 comments

I implemented the facebook messenger share button as follows :

<FacebookMessengerShareButton
            url={"https://www.google.com"}
            title={"please click me"}
            appId="521270401588372"
          >
            <FacebookMessengerIcon size={64} round />
          </FacebookMessengerShareButton>

and tried it with different mobile devices. It always gives the following error :

This dialog is not available on this device

Also i think it's safe to say to assume that since the component's name is FacebookMessengerShareButton the messenger app will open on your mobile device and if you're on browser then the normal facebook site will open. Instead when clicking on the button with a mobile device a new page will open with the facebook mobile version. I couldn't find any open issue about this, so is this a bug or the expected behavior ?

achraf-boussaada avatar Feb 24 '20 15:02 achraf-boussaada

with the following i was able to reach my goal :

        <button
          onClick={messengerOnClick}
          style={{
            backgroundColor: "transparent",
            border: "none",
            font: "inherit",
            color: "inherit",
            cursor: "pointer"
          }}
        >
          <FacebookMessengerIcon size={64} round />
        </button>

  const messengerOnClick = (
    event: React.MouseEvent<HTMLButtonElement, MouseEvent>
  ) => {
    window.open(
      "fb-messenger://share?link=" +
        encodeURIComponent("https://www.google.com") +
        "&app_id=" +
        encodeURIComponent("521270401588372")
    );
  };

source : https://developers.facebook.com/docs/sharing/messenger/web/ Maybe this is a feature to add, to allow sharind directly to facebook messenger on mobile

achraf-boussaada avatar Feb 25 '20 09:02 achraf-boussaada

But like this it will only work on mobile and throw an error on desktop, no?

stiwwelll avatar Apr 14 '20 09:04 stiwwelll

I can confirm that the solution of @achraf-boussaada works in mobile (in my case I needed to change window.location.href and not open a new window), but doesn't work in desktops.

bfintal avatar May 06 '20 17:05 bfintal

@bfintal Did it work on Chrome for iOS for you? Somehow I can't get it to work there. It works great with all other mobile browsers (Safari, FF). Also on Android (Chrome and FF).

stiwwelll avatar May 06 '20 18:05 stiwwelll

@stiwwelll Yes it works in Chrome iOS in mine. Here's what I have which is only shown in mobile:

<button className="react-share__ShareButton" style={ { background: '#3885f7' } }
	onClick={ () => {
		window.location.href =
			'fb-messenger://share?link=' +
			encodeURIComponent( `https://myurl` ) +
			'&app_id=' +
			encodeURIComponent( 123123123 )
	} }
>
	<FacebookMessengerIcon size={ 24 } bgStyle={{ fill: 'none' }} />
</button>

bfintal avatar May 07 '20 04:05 bfintal

It would be great if they can integrate some sort of device detection, to check if the user is using the mobile or the web version and accordingly display the right component.

achraf-boussaada avatar May 28 '20 09:05 achraf-boussaada

This is a good solution and i would recommend to integrate this feature what about facebook app can I do the same thing? what should i use instead of this URL fb-messenger://share?link=

Ghaleb-alnakhlani avatar Jan 31 '21 15:01 Ghaleb-alnakhlani