【问题标题】:Pass parameters to Facebook App Link from Android App从 Android 应用程序向 Facebook 应用程序链接传递参数
【发布时间】:2016-04-11 11:18:09
【问题描述】:

我正在使用以下代码向 Facebook 分享内容(例如文本、图片和应用链接):

第 1 步:

public void setupFacebookShareIntent() {

    ShareDialog shareDialog;

    FacebookSdk.sdkInitialize(getApplicationContext());
    shareDialog = new ShareDialog(this);

    ShareLinkContent linkContent = new ShareLinkContent.Builder()
            .setContentTitle(title)
            .setContentDescription(
                    text1+ " " +text2)
            .setContentUrl(Uri.parse("http://example/folder"))
            .setImageUrl(Uri.parse(path1))
            .build();

    shareDialog.show(linkContent);
}

这里还有应用链接元数据:

第 2 步:

<html>
<head>
    <meta property="al:android:url" content="sharesample://story/1234">
    <meta property="al:android:package" content="com.mypackage">
    <meta property="al:android:app_name" content="ShareSample">
    <meta property="og:title" content="example page title" />
    <meta property="og:type" content="website" />
</head>
<body>
</body>
</html>

这里是处理 Activity 中传入应用链接的代码:

第 3 步:

Uri targetUrl = AppLinks.getTargetUrlFromInboundIntent(this, getIntent());

        if (targetUrl != null) {

            // If you need to access data that you are passing from the meta tag from your website or from opening app you can get them from AppLinkData.
            Bundle applinkData = AppLinks.getAppLinkData(getIntent());
            String id = applinkData.getString("id");

            // You can also get referrer data from AppLinkData
            Bundle referrerAppData = applinkData.getBundle("referer_app_link");

        } else {
            // Not an applink, your existing code goes here.
        }

如何在第 1 步中正确地将数据传递给应用链接 url,例如简单的字符串参数,然后在 第 3 步中返回?

【问题讨论】:

  • 没人知道吗? :)

标签: android facebook share


【解决方案1】:

以防万一有人有同样的“问题”,我会发布我的解决方案:

当我从我的应用程序分享到 FB 的链接时,我会像这样在 url 中传递参数:

http://my-app.com/xxxx/xxx.php?id=10

然后如果用户点击 FB 上的链接,那么我的应用程序就会启动,我得到的参数如下:

 Uri targetUrl = AppLinks.getTargetUrlFromInboundIntent(this, getIntent());
 String s = targetUrl.getQueryParameter("id");

【讨论】:

  • 非常感谢辛。当我使用 facebook 应用程序链接服务时,我真的很想知道我该如何传递它的论点。但是您的解决方案非常完美。 (y)
  • 我在 11.3.0 stackoverflow.com/questions/69460312/… 中收到以下错误
猜你喜欢
  • 2016-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多