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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26106447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:00:37  来源:igfitidea点击:

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?

androidiosfacebookmobile

提问by Walker

Is it possible to have a share on Facebook linkon 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. Consequently the web share dialog prompts them to input their user credentials - which might lead them to not share after all.

现在点击 Facebook 分享链接会打开基于网络的分享对话框,这很糟糕,因为大多数移动 Facebook 用户都在使用本机应用程序,因此没有在他们的浏览器上登录。因此,网络共享对话框会提示他们输入他们的用户凭据——这可能最终导致他们不共享。

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!

在此先感谢您的帮助!

回答by jan.vogt

As of now, there is no official wayto achieve this. It couldbe implemented by Facebook though, forwarding their web share dialog using their custom URL scheme. So if you use the officially documented wayto open this dialog you would get this functionality with no further changes as soon as it becomes available.

到目前为止,还没有官方的方法来实现这一点。不过,它可以由 Facebook 实施,使用他们的自定义 URL 方案转发他们的网络共享对话框。因此,如果您使用官方记录的方式打开此对话框,您将在此功能可用后立即获得此功能,而无需进一步更改。

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. Or you include the Facebook JS-SDKand use the classical share button or other ways described in sharing on the web.

您可以使用正确的 URL 编码值替换 URL_TO_SHARE 和 RETURN_URL。或者您包含 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. See sharing from iOSor android. 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.

只是为了完整性:在 iOS 和 Android 上的本机应用程序中,如果用户安装了 Facebook 应用程序,则可以直接链接到 Facebook 应用程序。请参阅从iOSandroid共享。由于情况并非总是如此,您必须使用相应平台的特定 Facebook SDK 进行检查,并回退到基于 Web 的对话框。

On a sidenote: I would highly discourage you from using the not officially documented URL-schemes registered by the Facebook app. 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. Even if you check for all these cases, Facebook has already changed their URL-Schemesand might do so again at any time, breaking your link(s) or - maybe worse - leading to undefined behavior.

旁注:我强烈建议您不要使用 Facebook 应用程序注册的未正式记录的 URL 方案。如果从安装了 Facebook 应用程序的设备访问网站,它们可能会工作,但在没有安装 Facebook 应用程序的设备上,尤其是任何 PC 或 Mac 上,它们会变成死链接或奇怪的浏览器警告。即使您检查了所有这些情况,Facebook已经更改了他们的 URL-Schemes,并且可能会随时再次更改,从而破坏您的链接或者 - 可能更糟 - 导致未定义的行为。

回答by mon

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>

回答by Endran

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

尝试教程链接