简体   繁体   English

是否可以生成一个“在 Facebook 上分享”链接,在 Android/iOS/手机上打开原生 Facebook 应用程序而不是网络共享对话框?

[英]Is it possible to generate a 'share on Facebook' link that opens the native Facebook App on Android/iOS/mobile instead of the web share dialog?

Is it possible to have a share on Facebook link on a website that opens the share dialog in the native App ?是否可以在本机应用程序中打开共享对话框的网站上共享 Facebook 链接

Current behavior:当前行为:

Right now clicking the Facebook share link opens the web-based share dialog, which is bad since most mobile Facebook user are using the native app, thus are not logged in on their browsers.现在点击 Facebook 分享链接会打开基于网络的分享对话框,这很糟糕,因为大多数移动 Facebook 用户都在使用本机应用程序,因此没有在他们的浏览器上登录。 Consequently the web share dialog prompts them to input their user credentials - which might lead them to not share after all.因此,网络共享对话框会提示他们输入他们的用户凭据——这可能最终导致他们不共享。

Ideal behavior:理想行为:

Clicking the share on Facebook link leads to the share dialog in the native Facebook app, where the user is already signed in.单击 Facebook 上的共享链接会打开本地 Facebook 应用程序中的共享对话框,其中用户已登录。

Thanks in advance for the help!在此先感谢您的帮助!

As of now, there is no official way to achieve this.到目前为止,还没有官方的方法来实现这一点。 It could be implemented by Facebook though, forwarding their web share dialog using their custom URL scheme.不过,它可以由 Facebook 实施,使用他们的自定义 URL 方案转发他们的网络共享对话框。 So if you use the officially documented way to open this dialog you would get this functionality with no further changes as soon as it becomes available.因此,如果您使用官方记录的方式打开此对话框,您将在此功能可用后立即获得此功能,而无需进一步更改。

The easiest way to use the official web share dialog, without any prerequisites , is to link to this URL:无需任何先决条件,使用官方网络共享对话框的最简单方法是链接到此 URL:

https://www.facebook.com/dialog/share?
    app_id=145634995501895
    &display=popup
    &href=URL_TO_SHARE
    &redirect_uri=RETURN_URL

where you replace URL_TO_SHARE and RETURN_URL with the proper URL-encoded values.您可以使用正确的 URL 编码值替换 URL_TO_SHARE 和 RETURN_URL。 Or you include the Facebook JS-SDK and use the classical share button or other ways described in sharing on the web .或者您包含 Facebook JS-SDK并使用经典的分享按钮或在网络上分享中描述的其他方式。

Just for completeness: In native apps on iOS and Android it is possible to link to the Facebook app directly if the user has the Facebook app installed.只是为了完整性:在 iOS 和 Android 上的本机应用程序中,如果用户安装了 Facebook 应用程序,则可以直接链接到 Facebook 应用程序。 See sharing from iOS or android .请参阅从iOSandroid共享。 As this is not always the case you have to check using the respective platform's specific Facebook SDK and fallback to the web-based dialog as well.由于情况并非总是如此,您必须使用相应平台的特定 Facebook SDK 进行检查,并回退到基于 Web 的对话框。

On a sidenote: I would highly discourage you from using the not officially documented URL-schemes registered by the Facebook app.旁注:我强烈建议您不要使用 Facebook 应用程序注册的未正式记录的 URL 方案。 While they might work if the website is visited from a device with an installed Facebook app, they become dead links or weird browser warnings on devices without the Facebook app installed, especially any PCs or Macs.如果从安装了 Facebook 应用程序的设备访问网站,它们可能会工作,但在没有安装 Facebook 应用程序的设备上,尤其是任何 PC 或 Mac 上,它们会变成死链接或奇怪的浏览器警告。 Even if you check for all these cases, Facebook has already changed their URL-Schemes and might do so again at any time, breaking your link(s) or - maybe worse - leading to undefined behavior.即使您检查了所有这些情况,Facebook 已经更改了他们的 URL-Schemes,并且可能会随时再次更改,从而破坏您的链接或者 - 可能更糟 - 导致未定义的行为。

https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share

You could try this and let the user decide what native app to use when sharing your link.你可以试试这个,让用户决定在分享你的链接时使用哪个本机应用程序。

It opens the native share-via of the user's device它打开用户设备的本机共享通道

const data = {
  title: document.title,
  text: 'Hello World',
  url: 'https://your_site_url',
}

const shareVia = window.navigator.share(data);
<html>
 <button onClick={shareVia}>Share Me!</button>
</html>

The following code will check if the app is installed, if installed you can share using the app, you don't have to open Facebook in your web browser and log in again.下面的代码将检查是否安装了该应用程序,如果安装了您可以使用该应用程序进行分享,您不必在您的网络浏览器中打开 Facebook 并再次登录。 If the app is not installed it will simply use the Facebook sharer link then the user has to log in to Facebook in the browser if not logged in and the link gets shared.如果未安装该应用程序,它将仅使用 Facebook 共享者链接,如果未登录,则用户必须在浏览器中登录 Facebook 并共享该链接。

  onShare() {
    console.log(order);
    const title = 'Title';
    const url = 'https://www.facebook.com/';
    const text = "Share on native app if installed";
    if (navigator.share) {
      navigator
        .share({ title: `${title}`, url: `${url}`,text: `${text}`})
        .then(() => {
          console.log('Thanks for sharing!');
        })
        .catch(console.error);
    } else {
      window.location.replace(
        `https://www.facebook.com/sharer.php?u=${url.trim()}&quote=${text}`
      );
    }
  } //onShare ends here

 <a href="fb://page/100623981381289"> This is My page (click on your Phone installed facebook) </a>

I know it has been a couple of years, but for whom it may concern:我知道已经有几年了,但它可能会关注谁:
Have a look at this answer;看看这个答案; Xcode : sharing content via Action Sheet . Xcode:通过 Action Sheet 共享内容

Let me copy that answer overhere as well:让我也把那个答案复制到这里:

Swift迅速

let shareText = "Hello, world!"
if let image = UIImage(named: "myImage") {
    let vc = UIActivityViewController(activityItems: [shareText, image], applicationActivities: [])
    presentViewController(vc, animated: true, completion: nil)
}

Try links for tutorials尝试教程链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM