Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase dynamic link: can`t create short link

So, I've implemented FirebaseDynamicLinks like this:

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()
            }

but calling .buildShortDynamicLink() throws me an exception:

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]

and what's interesting: inserting test.page.link/generatedLongLink in browser works as intended - on android it directs me on google play page and on pc it directs me on web site that I specified in firebase consile when I was creating dynamic link

so what's the problem with calling .buildShortDynamicLink() and how can I fix it?

like image 977
Monka S Avatar asked Dec 18 '22 20:12

Monka S


1 Answers

I tried this code for you

    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()
        }

and it works fine.

If instead I didn't put "https://" on my dynamic link, I get your error.

enter image description here

So change

.setDomainUriPrefix("test.page.link")

with

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

And all should work fine:

enter image description here

like image 197
shadowsheep Avatar answered Jan 24 '23 17:01

shadowsheep