Android - Facebook共享内容被覆盖

Tim*_*Sim 19 android facebook

这是我在Facebook上分享高分的代码:

ShareLinkContent content = new ShareLinkContent.Builder()
  .setImageUrl(Uri.parse("http://www.example.com/myicon.png"))
  .setContentTitle("I scored "+numPoints+" points!")
  .setContentUrl(Uri.parse("https://play.google.com/store/apps/details?id=com.my.package"))
  .setContentDescription("Get the game free on Google Play and beat my score.")        
  .build();
ShareDialog shareDialog = new ShareDialog(this);
shareDialog.show(content);
Run Code Online (Sandbox Code Playgroud)

当URL是一些随机网站(如developers.facebook.com)时,这很有用,但是当它是Google Play的链接时,内容标题和内容描述会被覆盖 - 标题会被Play商店的标题和内容描述覆盖是空白的.

那么如何链接到Play商店的应用程序,但保留自定义标题和描述?我知道这是可能的,因为我见过其他应用程序这样做:

在此输入图像描述

mpk*_*uth 4

这篇文章的副本,其中包含Facebook 错误报告的链接,其中 Facebook 确认了该行为,并声明他们可能不会修复该问题。

至于其他应用程序如何获得这种行为,我有一个猜测。

如果您的应用程序有一个可以添加虚拟页面的网站,那么您可以执行以下操作:

<html>
  <head>
    <script type="text/javascript">
      window.location.replace('https://play.google.com/store/apps/details?id=com.example.client');
    </script>
  </head>
  <body></body>
</html>
Run Code Online (Sandbox Code Playgroud)

然后使用setContentUrl(Uri.parse("https://example.com/android")ShareDialogurl 打开一个提供上述 HTML 的页面。

当用户打开 Google Play 商店页面时,这会自动将其发送至该页面。后退按钮应该仍然有效,就像直接进入 Google Play 商店页面一样。

我尝试只使用 HTTP 重定向,而不是实际托管该页面,但这不起作用。


编辑:您可以在页面标题中包含AppLinks元标记,以跳过 Android 设备上的重定向。

<html>
<head><title>App Link</title>
    <meta property="fb:app_id" content="XXXXXXXXXXXXXXX"/>
    <meta property="al:ios:url" content="example://test"/>
    <meta property="al:ios:app_name" content="Example App"/>
    <meta property="al:ios:app_store_id" content="XXXXXXXXX"/>
    <meta property="al:android:package" content="com.example.client"/>
    <meta property="al:android:app_name" content="Example App"/>
    <meta property="al:android:url" content="example://test"/>
    <meta property="al:web:should_fallback" content="false"/>
    <meta http-equiv="refresh" content="0;url=http://play.google.com/store/apps/details?id=com.example.client"/>
</head>
<body>Redirecting...</body>
</html>
Run Code Online (Sandbox Code Playgroud)

向您展示了如何处理应用程序中的链接。

<activity
    android:name="com.example.client.MainActivity"
    android:label="@string/app_name">

    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>

    <intent-filter>
        <data android:scheme="example"/>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
    </intent-filter>

</activity>
Run Code Online (Sandbox Code Playgroud)

如果设备上未安装该应用程序,那么您将被发送到 Google Play 商店(尽管是通过一个非常丑陋的弹出窗口,当直接使用 Play 商店链接时,在正常的 ShareDialog 流程中不会发生这种情况)。

此外,如果您愿意,Facebook 将为您创建并托管该页面。上面的示例 HTML 来自其托管页面之一(请注意重定向的不同实现)。