Firebase动态链接:无法创建短链接

时间:2018-11-01 15:42:10

标签: android firebase firebase-dynamic-links

因此,我已经实现了FirebaseDynamicLinks

val link = "https://test/?promo=$uId"
    FirebaseDynamicLinks.getInstance().createDynamicLink()
            .setLink(Uri.parse(link))
            .setDomainUriPrefix("test.page.link")
            .setAndroidParameters(
                    DynamicLink.AndroidParameters.Builder("test")
                            .setMinimumVersion(1)
                            .build())
            .buildShortDynamicLink()
            .addOnSuccessListener { shortDynamicLink ->
                val mInvitationUrl = shortDynamicLink.shortLink.toString()
                log("test1 success $mInvitationUrl")
                //shareIntent(mInvitationUrl)
            }
            .addOnFailureListener {
                log("test1 fail")
                it.printStackTrace()
            }

但致电.buildShortDynamicLink()会引发异常:

W: com.google.android.gms.common.api.ApiException: 400: Long link is not parsable: test.page.link/generatedLongLink [https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_parameters]

有趣的是:在浏览器中插入test.page.link/generatedLongLink可以按预期工作-在android上,它将我定向到google play页面上,在pc上,将我定向到我在创建动态链接时在firebase consile中指定的网站上< / p>

那么调用.buildShortDynamicLink()有什么问题,我该如何解决?

1 个答案:

答案 0 :(得分:1)

我为您尝试了此代码

    val uId = 1234241

    val link = "https://www.test.com/$uId"
    FirebaseDynamicLinks.getInstance().createDynamicLink()
        .setLink(Uri.parse(link))
        .setDomainUriPrefix("https://example.page.link")
        .setAndroidParameters(
            DynamicLink.AndroidParameters.Builder("test")
                .setMinimumVersion(1)
                .build())
        .buildShortDynamicLink()
        .addOnSuccessListener { shortDynamicLink ->
            val mInvitationUrl = shortDynamicLink.shortLink.toString()
            Log.d("AAA","test1 success $mInvitationUrl")
            //shareIntent(mInvitationUrl)
        }
        .addOnFailureListener {
            Log.d("AAA", "test1 fail")
            it.printStackTrace()
        }

工作正常

如果我没有在动态链接上放置“ https://” ,则会收到您的错误消息。

enter image description here

所以改变

.setDomainUriPrefix("test.page.link")

.setDomainUriPrefix("https://test.page.link")

一切都应该正常工作

enter image description here